SphinxBase
5prealpha
|
Fast linked list allocator. More...
Data Fields | |
char ** | freelist |
ptr to first element in freelist | |
glist_t | blocks |
Linked list of blocks allocated. More... | |
glist_t | blocksize |
Number of elements in each block. | |
size_t | elemsize |
Number of (char *) in element. | |
size_t | blk_alloc |
Number of alloc operations before increasing blocksize. | |
size_t | n_blocks |
size_t | n_alloc |
size_t | n_freed |
Fast linked list allocator.
We keep a separate linked list for each element-size. Element-size must be a multiple of pointer-size.
Initially a block of empty elements is allocated, where the first machine word in each element points to the next available element. To allocate, we use this pointer to move the freelist to the next element, then return the current element.
The last element in the list starts with a NULL pointer, which is used as a signal to allocate a new block of elements.
In order to be able to actually release the memory allocated, we have to add a linked list of block pointers. This shouldn't create much overhead since we never access it except when freeing the allocator.
Definition at line 65 of file listelem_alloc.c.
glist_t listelem_alloc_s::blocks |
Linked list of blocks allocated.
Definition at line 67 of file listelem_alloc.c.
Referenced by listelem_get_item(), and listelem_stats().