当前位置: 首页>>代码示例>>C++>>正文


C++ Allocator::allocate方法代码示例

本文整理汇总了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);
     }
 }
开发者ID:peterprokop,项目名称:Allocators,代码行数:10,代码来源:allocators.hpp

示例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;
 }
开发者ID:imos,项目名称:icfpc2015,代码行数:25,代码来源:allocator_version_traits.hpp

示例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; }
}
开发者ID:robbriggs,项目名称:masters-project-nanosxx,代码行数:26,代码来源:allocator_01.cpp

示例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;
			}
开发者ID:Zoxc,项目名称:Prelude,代码行数:34,代码来源:HashTable.hpp

示例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 );
 }
开发者ID:hpcdev,项目名称:xylose,代码行数:8,代码来源:Stack.hpp

示例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;
}
开发者ID:RobertoMalatesta,项目名称:crown,代码行数:33,代码来源:pool_allocator.cpp

示例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);
     }
   }
开发者ID:LoliGothick,项目名称:2nd,代码行数:8,代码来源:05_alias_templates.cpp

示例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();
 }
开发者ID:imos,项目名称:icfpc2015,代码行数:8,代码来源:allocator_version_traits.hpp

示例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);
}
开发者ID:299299,项目名称:NagaGame,代码行数:9,代码来源:linear_allocator.cpp

示例10:

LinearAllocator::LinearAllocator(Allocator& backing, uint32_t size)
	: _backing(&backing)
	, _physical_start(NULL)
	, _total_size(size)
	, _offset(0)
{
	_physical_start = backing.allocate(size);
}
开发者ID:RobertoMalatesta,项目名称:crown,代码行数:8,代码来源:linear_allocator.cpp

示例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();
    }
开发者ID:unitsea-developer,项目名称:ET4QA,代码行数:8,代码来源:cache_table.hpp

示例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);
        }
开发者ID:akashihi,项目名称:stlcache,代码行数:19,代码来源:stlcache.hpp

示例13: Simple

  void Simple()
  {
    Allocator<DummyClass> allocator;

    DummyClass* p = allocator.allocate(1);
    allocator.construct(p, DummyClass());
    allocator.destroy(p);
    allocator.deallocate(p, 1);
  }
开发者ID:mutac,项目名称:Magnetometer,代码行数:9,代码来源:TestAllocator.cpp

示例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);
}
开发者ID:komiga,项目名称:quanta,代码行数:10,代码来源:unmanaged_string.cpp

示例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 );
   }
 }
开发者ID:hpcdev,项目名称:xylose,代码行数:11,代码来源:Stack.hpp


注:本文中的Allocator::allocate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。