NEST
2.6.0,not_revisioned_source_dir@0
|
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>
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... | |
chunk * | chunks_ |
First element of the linked list of chunks. More... | |
size_t | capacity_ |
Remaining capacity of the current chunk. More... | |
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.
void * PoorMansAllocator::alloc | ( | size_t | obj_size | ) |
Referenced by allocate(), and suicide_and_resurrect().
void PoorMansAllocator::destruct | ( | ) |
References PoorMansAllocator::chunk::next_.
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().
|
private |
Append a new chunk of memory to the list forming the memory pool.
|
private |
Remaining capacity of the current chunk.
|
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).
|
private |
First element of the linked list of chunks.
|
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.