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. | |
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.
size_t listelem_alloc_s::blk_alloc |
Number of alloc operations before increasing blocksize.
Definition at line 70 of file listelem_alloc.c.
Referenced by listelem_alloc_init().
glist_t listelem_alloc_s::blocks |
Linked list of blocks allocated.
Definition at line 67 of file listelem_alloc.c.
Referenced by listelem_alloc_free(), listelem_alloc_init(), listelem_get_item(), and listelem_stats().
glist_t listelem_alloc_s::blocksize |
Number of elements in each block.
Definition at line 68 of file listelem_alloc.c.
Referenced by listelem_alloc_free(), and listelem_stats().
size_t listelem_alloc_s::elemsize |
Number of (char *) in element.
Definition at line 69 of file listelem_alloc.c.
Referenced by listelem_alloc_init(), listelem_get_item(), and listelem_stats().
char** listelem_alloc_s::freelist |
ptr to first element in freelist
Definition at line 66 of file listelem_alloc.c.
Referenced by __listelem_free__(), listelem_alloc_init(), and listelem_stats().
size_t listelem_alloc_s::n_alloc |
Definition at line 72 of file listelem_alloc.c.
size_t listelem_alloc_s::n_blocks |
Definition at line 71 of file listelem_alloc.c.
size_t listelem_alloc_s::n_freed |
Definition at line 73 of file listelem_alloc.c.