本文整理汇总了C++中bslma::Allocator::allocate方法的典型用法代码示例。如果您正苦于以下问题:C++ Allocator::allocate方法的具体用法?C++ Allocator::allocate怎么用?C++ Allocator::allocate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bslma::Allocator
的用法示例。
在下文中一共展示了Allocator::allocate方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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);
}
示例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;
}
示例5: 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 = '?';
}
示例6:
// 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;
}
示例7: 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;
}
}
示例8: 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);
}
示例9: 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;
}
示例10: 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];
}
}
}
示例11:
// MANIPULATORS
void *my_Allocator::allocate(size_type size)
{
return d_allocator_p->allocate(size);
}
示例12:
my_Type(int size, bslma::Allocator *basicAllocator)
: d_allocator_p(basicAllocator)
{
d_stuff_p = (char *) d_allocator_p->allocate(size);
}