本文整理汇总了C++中bslma::Allocator类的典型用法代码示例。如果您正苦于以下问题:C++ Allocator类的具体用法?C++ Allocator怎么用?C++ Allocator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Allocator类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: strcpy
// CREATORS
inline
my_Id::my_Id(const char *id, bslma::Allocator *basicAllocator)
: d_allocator_p(bslma::Default::allocator(basicAllocator))
{
d_buffer_p = (char *)d_allocator_p->allocate(strlen(id) + 1);
strcpy(d_buffer_p, id);
}
开发者ID:RMGiroux,项目名称:bde,代码行数:8,代码来源:bslma_default.t.cpp
示例2: UsageType
// CREATORS
explicit UsageType(char c, bslma::Allocator *basicAllocator = 0)
: d_data_p(0)
, d_allocator_p(bslma::Default::allocator(basicAllocator))
{
d_data_p = (char *)d_allocator_p->allocate(sizeof(char));
*d_data_p = c;
}
开发者ID:Stackingit,项目名称:bde,代码行数:8,代码来源:bslalg_autoarraydestructor.t.cpp
示例3: TestType
// CREATORS
explicit TestType(bslma::Allocator *basicAllocator = 0)
: d_data_p(0)
, d_allocator_p(bslma::Default::allocator(basicAllocator))
{
++numDefaultCtorCalls;
d_data_p = (char *)d_allocator_p->allocate(sizeof(char));
*d_data_p = '?';
}
开发者ID:azakhar,项目名称:bsl,代码行数:9,代码来源:bslalg_autoarraymovedestructor.t.cpp
示例4: TestType
explicit TestType(char c, bslma::Allocator *ba = 0)
: d_data_p(0)
, d_allocator_p(bslma::Default::allocator(ba))
{
++numCharCtorCalls;
d_data_p = (char *)d_allocator_p->allocate(sizeof(char));
*d_data_p = c;
}
开发者ID:AlisdairM,项目名称:bde,代码行数:8,代码来源:bslalg_arraydestructionprimitives.t.cpp
示例5: HashCrossReference
// CREATORS
HashCrossReference(const TYPE *valuesArray,
size_t numValues,
bslma::Allocator *allocator = 0)
// Create a hash cross reference referring to the array of value.
: d_values(valuesArray)
, d_numValues(numValues)
, d_hasher()
, d_valid(true)
, d_allocator_p(bslma::Default::allocator(allocator))
{
size_t bucketArrayLength = 4;
while (bucketArrayLength < numValues * 4) {
bucketArrayLength *= 2;
BSLS_ASSERT_OPT(bucketArrayLength);
}
d_bucketArrayMask = bucketArrayLength - 1;
d_bucketArray = (const TYPE **) d_allocator_p->allocate(
bucketArrayLength * sizeof(TYPE **));
memset(d_bucketArray, 0, bucketArrayLength * sizeof(TYPE *));
for (unsigned i = 0; i < numValues; ++i) {
const TYPE& value = d_values[i];
size_t idx;
if (lookup(&idx, value, d_hasher(value))) {
// Duplicate value. Fail.
printf("Error: entries %u and %u have the same value\n",
i, (unsigned) (d_bucketArray[idx] - d_values));
d_valid = false;
// don't return, continue reporting other redundant entries.
}
else {
d_bucketArray[idx] = &d_values[i];
}
}
}
开发者ID:azakhar,项目名称:bsl,代码行数:38,代码来源:bslstl_hash.t.cpp
示例6: my_Type
my_Type(int size, bslma::Allocator *basicAllocator)
: d_allocator_p(basicAllocator)
{
d_stuff_p = (char *) d_allocator_p->allocate(size);
}
开发者ID:PeterMartini,项目名称:bsl,代码行数:5,代码来源:bslma_allocator.t.cpp
示例7: deallocate
void my_Allocator::deallocate(void *address)
{
d_allocator_p->deallocate(address);
}
开发者ID:bowlofstew,项目名称:bde-allocator-benchmarks,代码行数:4,代码来源:bslma_mallocfreeallocator.t.cpp
示例8:
// MANIPULATORS
void *my_Allocator::allocate(size_type size)
{
return d_allocator_p->allocate(size);
}
开发者ID:bowlofstew,项目名称:bde-allocator-benchmarks,代码行数:5,代码来源:bslma_mallocfreeallocator.t.cpp
示例9: autoReleaser
//..
// Finally, we implement 'my_FastCstrArray::operator=' using a
// 'bdlma::AutoReleaser' proctor to preserve exception neutrality:
//..
// // my_fastcstrarray.cpp
// #include <my_fastcstrarray.h>
//
// // ...
//
// MANIPULATORS
my_FastCstrArray&
my_FastCstrArray::operator=(const my_FastCstrArray& rhs)
{
if (&rhs != this) {
d_strPool.release();
d_length = 0;
if (rhs.d_length > d_capacity) {
char **tmp = d_array_p;
d_array_p = (char **)d_allocator_p->allocate(
rhs.d_length * sizeof *d_array_p);
d_capacity = rhs.d_length;
d_allocator_p->deallocate(tmp);
}
bdlma::AutoReleaser<my_StrPool> autoReleaser(&d_strPool);
for (int i = 0; i < rhs.d_length; ++i) {
const int size = bsl::strlen(rhs.d_array_p[i]) + 1;
d_array_p[i] = (char *)d_strPool.allocate(size);
bsl::memcpy(d_array_p[i], rhs.d_array_p[i], size);
}
d_length = rhs.d_length;
autoReleaser.release();
}
return *this;
}
开发者ID:kpfleming,项目名称:bde,代码行数:39,代码来源:bdlma_autoreleaser.t.cpp
示例10:
// MANIPULATORS
TestType& operator=(const TestType& rhs)
{
++numAssignmentCalls;
if (&rhs != this) {
char *newData = (char *)d_allocator_p->allocate(sizeof(char));
*d_data_p = '_';
d_allocator_p->deallocate(d_data_p);
d_data_p = newData;
*d_data_p = *rhs.d_data_p;
}
return *this;
}
开发者ID:AlisdairM,项目名称:bde,代码行数:13,代码来源:bslalg_arraydestructionprimitives.t.cpp
示例11: setDescription
// MANIPULATORS
inline
void MyClass::setDescription(const char *value)
{
BSLS_ASSERT_SAFE(value);
size_t size = strlen(value) + 1;
if (size > d_capacity) {
char *newMemory = (char *) d_allocator_p->allocate(size);
d_allocator_p->deallocate(d_description_p);
d_description_p = newMemory;
d_capacity = size;
}
memcpy(d_description_p, value, size);
}
开发者ID:AlisdairM,项目名称:bde,代码行数:16,代码来源:bslma_testallocatormonitor.t.cpp
示例12:
inline
MyClass::~MyClass()
{
BSLS_ASSERT_SAFE(0 <= d_capacity);
d_allocator_p->deallocate(d_description_p);
}
开发者ID:AlisdairM,项目名称:bde,代码行数:7,代码来源:bslma_testallocatormonitor.t.cpp
示例13:
~ListSet()
// Release all memory used by this 'ListSet'
{
for (Node *node = d_nodeList; node; ) {
Node *toDelete = node;
node = node->d_next;
d_allocator_p->deleteObject(toDelete);
}
}
开发者ID:PeterMartini,项目名称:bsl,代码行数:10,代码来源:bslstl_equalto.t.cpp
示例14: allocate
void testBlobBufferFactory::allocate(btlb::BlobBuffer *buffer)
{
bsl::shared_ptr<char> shptr(
(char *) d_allocator_p->allocate(d_currentBufferSize),
d_allocator_p);
buffer->reset(shptr, d_currentBufferSize);
if (d_growFlag && d_currentBufferSize < 1024) {
d_currentBufferSize *= 2;
}
}
开发者ID:che2,项目名称:bde,代码行数:12,代码来源:btlb_blobstreambuf.t.cpp
示例15: insert
// MANIPULATOR
bool insert(const TYPE& value)
// If 'value' isn't contained in this 'ListSet', add it and return
// 'true', otherwise, return 'false' with no change to the 'ListSet'.
{
if (count(value)) {
return false; // RETURN
}
Node *node = (Node *) d_allocator_p->allocate(sizeof(Node));
bslalg::ScalarPrimitives::copyConstruct(&node->d_value,
value,
d_allocator_p);
node->d_next = d_nodeList;
d_nodeList = node;
return true;
}
开发者ID:PeterMartini,项目名称:bsl,代码行数:18,代码来源:bslstl_equalto.t.cpp
示例16:
~UsageType()
{
*d_data_p = '_';
d_allocator_p->deallocate(d_data_p);
d_data_p = 0;
}
开发者ID:Stackingit,项目名称:bde,代码行数:6,代码来源:bslalg_autoarraydestructor.t.cpp
示例17: disposeRep
void MySharedDatetimeRepImpl::disposeRep() {
d_allocator_p->deallocate(this);
}
开发者ID:SuperV1234,项目名称:bde,代码行数:3,代码来源:bslma_sharedptrrep.t.cpp
示例18:
~my_Type()
{
d_allocator_p->deallocate(d_stuff_p);
}
开发者ID:PeterMartini,项目名称:bsl,代码行数:4,代码来源:bslma_allocator.t.cpp
示例19:
inline
my_Id::~my_Id()
{
d_allocator_p->deallocate(d_buffer_p);
}
开发者ID:RMGiroux,项目名称:bde,代码行数:5,代码来源:bslma_default.t.cpp
示例20:
~HashCrossReference()
// Free up memory used by this cross-reference.
{
d_allocator_p->deallocate(d_bucketArray);
}
开发者ID:azakhar,项目名称:bsl,代码行数:5,代码来源:bslstl_hash.t.cpp
注:本文中的bslma::Allocator类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论