本文整理汇总了C++中Allocator::allocate方法的典型用法代码示例。如果您正苦于以下问题:C++ Allocator::allocate方法的具体用法?C++ Allocator::allocate怎么用?C++ Allocator::allocate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Allocator
的用法示例。
在下文中一共展示了Allocator::allocate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: allocate
AllocatorBlock allocate(size_t n) {
if (n > max) {
return {nullptr, 0};
} if ( (n - min) % step == 0) {
return parent_.allocate(n);
} else {
auto delta = (n - min)/step + 1;
return parent_.allocate(min + delta * step);
}
}
示例2: ret
static std::pair<pointer, bool>
allocation_command(Allocator &a, allocation_type command,
size_type, size_type preferred_size,
size_type &received_size, const pointer &)
{
std::pair<pointer, bool> ret(pointer(), false);
if(!(command & allocate_new)){
if(!(command & nothrow_allocation)){
throw_logic_error("version 1 allocator without allocate_new flag");
}
}
else{
received_size = preferred_size;
BOOST_TRY{
ret.first = a.allocate(received_size);
}
BOOST_CATCH(...){
if(!(command & nothrow_allocation)){
BOOST_RETHROW
}
}
BOOST_CATCH_END
}
return ret;
}
示例3: main
int main (int argc, char **argv)
{
bool check = true;
Allocator allocator;
for ( int n = 0; n < TIMES; n++ ) {
for ( unsigned int i = 0; i < (sizeof( sizes )/sizeof(int)); i++ ) {
int *ptr = (int *) allocator.allocate( sizes[i] * sizeof(int) );
if ( ptr == NULL ) check = false;
for ( int j = 0; j < sizes[i]; j++ ) ptr[j] = CHECK_VALUE; // INI
for ( int j = 0; j < sizes[i]; j++ ) ptr[j]++; // INC
for ( int j = 0; j < sizes[i]; j++ ) ptr[j]--; // DEC
// Check result
for ( int j = 0; j < sizes[i]; j++ ) {
if ( ptr[j] != CHECK_VALUE ) exit(-1);
}
Allocator::deallocate( ptr );
}
}
if (check) { return 0; } else { return -1; }
}
示例4: expand
void expand()
{
size_t size = (this->mask + 1) << 1;
size_t mask = size - 1;
Table table = allocator.allocate(size);
if(!Allocator::null_references)
for(size_t i = 0; i < size; ++i)
table[i] = T::invalid_value();
V *end = this->table + (this->mask + 1);
for(V *slot = this->table; slot != end; ++slot)
{
V entry = *slot;
while(T::valid_value(entry))
{
T::verify_value(entry);
V next = T::get_value_next(entry);
store(table, mask, T::get_key(entry), entry);
entry = next;
}
}
allocator.free(this->table);
this->mask = mask;
this->table = table;
}
示例5: Stack
/// construct a stack with 0 elements and an initial capacity of 128
Stack() :
mData( NULL ),
mSize( 0 ),
mCapacity( kInitialSize ),
mAlloc() {
mData = mAlloc.allocate( kInitialSize );
}
示例6:
PoolAllocator::PoolAllocator(Allocator& backing, uint32_t num_blocks, uint32_t block_size, uint32_t block_align)
: _backing(backing)
, _start(NULL)
, _freelist(NULL)
, _block_size(block_size)
, _block_align(block_align)
, _num_allocations(0)
, _allocated_size(0)
{
CE_ASSERT(num_blocks > 0, "Unsupported number of blocks");
CE_ASSERT(block_size > 0, "Unsupported block size");
CE_ASSERT(block_align > 0, "Unsupported block alignment");
uint32_t actual_block_size = block_size + block_align;
uint32_t pool_size = num_blocks * actual_block_size;
char* mem = (char*) backing.allocate(pool_size, block_align);
// Initialize intrusive freelist
char* cur = mem;
for (uint32_t bb = 0; bb < num_blocks - 1; bb++)
{
uintptr_t* next = (uintptr_t*) cur;
*next = (uintptr_t) cur + actual_block_size;
cur += actual_block_size;
}
uintptr_t* end = (uintptr_t*) cur;
*end = (uintptr_t) NULL;
_start = mem;
_freelist = mem;
}
示例7: Stack
explicit Stack(int n) : capacity_(n), index_(0)
{
Allocator alloc;
data_ = alloc.allocate(capacity_);
for (int i = 0; i < capacity_; ++i) {
alloc.construct(data_ + i);
}
}
示例8: allocate_individual
static void allocate_individual(Allocator &a, size_type n, multiallocation_chain &m)
{
allocate_individual_rollback rollback(a, m);
while(n--){
m.push_front(a.allocate(1));
}
rollback.release();
}
示例9:
//-----------------------------------------------------------------------------
LinearAllocator::LinearAllocator(Allocator& backing, size_t size)
: m_backing(&backing)
, m_physical_start(NULL)
, m_total_size(size)
, m_offset(0)
{
m_physical_start = backing.allocate(size);
}
示例10:
LinearAllocator::LinearAllocator(Allocator& backing, uint32_t size)
: _backing(&backing)
, _physical_start(NULL)
, _total_size(size)
, _offset(0)
{
_physical_start = backing.allocate(size);
}
示例11: init
void init()
{
m_table = m_allocator.allocate( m_buckets * ItemSize );
m_end_marker = m_table + m_buckets;
m_end_it = iterator( this, m_end_marker );
initialize_memory();
}
示例12: cache
/*!
* \brief Primary constructor.
*
* Constructs an empty cache object and sets a maximum size for it. It is the only way to set size for a cache and it can't be changed later.
* You could also pass optional comparator object, compatible with Compare.
*
* \param <size> Maximum number of entries, allowed in the cache.
* \param <comp> Comparator object, compatible with Compare type. Defaults to Compare()
*
*/
explicit cache(const size_type size, const Compare& comp = Compare()) {
this->_storage=storageType(comp, Allocator<pair<const Key, Data> >());
this->_maxEntries=size;
this->_currEntries=0;
policy_type localPolicy(size);
this->_policy = policyAlloc.allocate(1);
policyAlloc.construct(this->_policy,localPolicy);
}
示例13: Simple
void Simple()
{
Allocator<DummyClass> allocator;
DummyClass* p = allocator.allocate(1);
allocator.construct(p, DummyClass());
allocator.destroy(p);
allocator.deallocate(p, 1);
}
示例14: set
/// Set value.
void unmanaged_string::set(UnmanagedString& s, StringRef value, Allocator& a) {
unmanaged_string::clear(s, a);
if (value.empty()) {
return;
}
s.size = value.size;
s.data = static_cast<char*>(a.allocate(s.size + 1));
string::copy(s.data, s.size + 1, value);
}
示例15: reserve
/// Reserve enough space for n elements
void reserve( size_type n ) {
if ( mCapacity < n ) {
size_type oldCapacity = mCapacity;
pointer oldData = mData;
mCapacity = n;
mData = mAlloc.allocate( mCapacity );
std::uninitialized_copy( oldData, oldData + mSize, mData );
mAlloc.deallocate( oldData, oldCapacity );
}
}