NEST  2.6.0,not_revisioned_source_dir@0
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
sli::pool Class Reference

pool is a specialized allocator class for many identical small objects. More...

#include <allocator.h>

Classes

class  chunk
 
struct  link
 

Public Member Functions

 pool ()
 Create pool for objects of size n. More...
 
 pool (const pool &)
 
pooloperator= (const pool &)
 
 pool (size_t n, size_t initial=100, size_t growth=1)
 
void init (size_t n, size_t initial=100, size_t growth=1)
 
 ~pool ()
 deallocate ALL memory More...
 
void reserve_additional (size_t n)
 Increase the pools capacity (free slots) by n. More...
 
size_t available (void) const
 
void * alloc (void)
 allocate one element More...
 
void free (void *p)
 put element back into the pool More...
 
size_t size_of (void) const
 
size_t get_el_size () const
 
size_t get_instantiations () const
 
size_t get_total () const
 

Private Member Functions

void grow (size_t)
 make pool larger by n elements More...
 
void grow ()
 make pool larger More...
 

Private Attributes

size_t initial_block_size
 
size_t growth_factor
 
size_t block_size
 number of elements per chunk More...
 
size_t el_size
 sizeof an element More...
 
size_t instantiations
 number of instantiated elements More...
 
size_t total
 total number of allocated elements More...
 
size_t capacity
 number of free elements More...
 
chunkchunks
 linked list of memory chunks More...
 
linkhead
 head of free list More...
 
bool initialized_
 True if the pool is initialized. More...
 

Detailed Description

pool is a specialized allocator class for many identical small objects.

It targets a performance close to the optimal performance which is achieved by allocating all needed objects at once.

Constructor & Destructor Documentation

sli::pool::pool ( )

Create pool for objects of size n.

Initial is the initial allocation block size, i.e. the number of objects per block. growth is the factor by which the allocations block increases after each growth.

sli::pool::pool ( const pool p)
sli::pool::pool ( size_t  n,
size_t  initial = 100,
size_t  growth = 1 
)
sli::pool::~pool ( )

deallocate ALL memory

References nest::names::n, sli::pool::chunk::next, and nest::names::p.

Member Function Documentation

void * sli::pool::alloc ( void  )
inline
size_t sli::pool::available ( void  ) const
inline

References instantiations, and total.

void sli::pool::free ( void *  p)
inline
size_t sli::pool::get_el_size ( ) const
inline

References el_size.

size_t sli::pool::get_instantiations ( ) const
inline

References instantiations.

size_t sli::pool::get_total ( ) const
inline

References total.

void sli::pool::grow ( size_t  nelements)
private
void sli::pool::grow ( void  )
private

make pool larger

Referenced by alloc().

void sli::pool::init ( size_t  n,
size_t  initial = 100,
size_t  growth = 1 
)
sli::pool & sli::pool::operator= ( const pool p)
void sli::pool::reserve_additional ( size_t  n)

Increase the pools capacity (free slots) by n.

reserve_additional() ensures that the pool has at least n empty slots, i.e., that the pool can store at least n additional elements before more memory needs to be allocated from the operating system.

size_t sli::pool::size_of ( void  ) const
inline

Member Data Documentation

size_t sli::pool::block_size
private

number of elements per chunk

Referenced by alloc().

size_t sli::pool::capacity
private

number of free elements

chunk* sli::pool::chunks
private

linked list of memory chunks

size_t sli::pool::el_size
private

sizeof an element

Referenced by get_el_size(), operator=(), and size_of().

size_t sli::pool::growth_factor
private

Referenced by alloc(), and operator=().

link* sli::pool::head
private

head of free list

Referenced by alloc(), and free().

size_t sli::pool::initial_block_size
private

Referenced by operator=().

bool sli::pool::initialized_
private

True if the pool is initialized.

size_t sli::pool::instantiations
private

number of instantiated elements

Referenced by alloc(), available(), free(), and get_instantiations().

size_t sli::pool::total
private

total number of allocated elements

Referenced by available(), and get_total().


The documentation for this class was generated from the following files: