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

The poor man's allocator is a simple pool-based allocator, used to allocate storage for connections in the limit of large machines. More...

#include <allocator.h>

Inheritance diagram for PoorMansAllocator:
PaddedPMA

Classes

struct  chunk
 A chunk of memory, one element in the linked list of the memory pool. More...
 

Public Member Functions

void init (size_t chunk_size=1048576)
 No constructors, as this would be counted as a 'use' of the pool before declaring it thread-private by the compiler. More...
 
void destruct ()
 
void * alloc (size_t obj_size)
 

Private Member Functions

void new_chunk ()
 Append a new chunk of memory to the list forming the memory pool. More...
 

Private Attributes

size_t chunk_size_
 The size of each chunk to be allocated. More...
 
char * head_
 Points to the next free location in the current chunk. More...
 
chunkchunks_
 First element of the linked list of chunks. More...
 
size_t capacity_
 Remaining capacity of the current chunk. More...
 

Detailed Description

The poor man's allocator is a simple pool-based allocator, used to allocate storage for connections in the limit of large machines.

The allocator only supports allocation, but no freeing. In the limit of large machines this is sufficient, because we rarely need to grow synapse lists, as the majority of neurons have at most one target per machine. The allocator manages the pool of free memory in chunks that form a linked list. A head pointer keeps track of the next position in a chunk to be handed to the caller of allocate. Once head reaches the end of the current chunk, a new chunk is allocated from the OS and appends it to the linked list of chunks.

Member Function Documentation

void * PoorMansAllocator::alloc ( size_t  obj_size)

Referenced by allocate(), and suicide_and_resurrect().

void PoorMansAllocator::destruct ( )
void PoorMansAllocator::init ( size_t  chunk_size = 1048576)

No constructors, as this would be counted as a 'use' of the pool before declaring it thread-private by the compiler.

Therefore we have our own init() and destruct() functions.

Referenced by nest::Scheduler::prepare_nodes().

void PoorMansAllocator::new_chunk ( )
private

Append a new chunk of memory to the list forming the memory pool.

Member Data Documentation

size_t PoorMansAllocator::capacity_
private

Remaining capacity of the current chunk.

size_t PoorMansAllocator::chunk_size_
private

The size of each chunk to be allocated.

This size must be chosen as a tradeoff between few allocations of chunks (large chunk) and little memory overhead due to unused chunks (small chunks).

chunk* PoorMansAllocator::chunks_
private

First element of the linked list of chunks.

char* PoorMansAllocator::head_
private

Points to the next free location in the current chunk.

This location will be handed to the caller in the next call of allocate. The type is char*, so that pointer arithmetic allows adding sizeof(object) directly to advance the pointer to the next free location.


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