|
Zero
0.1.0
|
#include <mem_mgmt.h>
Classes | |
| class | list_header_t |
| struct | slot_t |
Public Member Functions | |
| fixed_lists_mem_t (size_t bufsize=8192 *10240, size_t incr=32, size_t max=16384) | |
| ~fixed_lists_mem_t () | |
| rc_t | allocate (size_t length, slot_t &slot) |
| rc_t | free (slot_t slot) |
| rc_t | defrag () |
Private Member Functions | |
| void | add_to_list (size_t block_size, char *address) |
| char * | remove_from_list (size_t block_size) |
| void | remove_from_list (list_header_t *p) |
| bool | is_list_empty (size_t block_size) |
Private Attributes | |
| const size_t | _incr |
| const size_t | _max |
| size_t | _bufsize |
| list_header_t ** | _lists |
| char * | _buf |
| size_t | _first_non_empty |
| size_t | _last_non_empty |
| size_t | _alloc |
| size_t | _used |
Memory management algorithm as proposed in:
P. Larson: External sorting: run formation revisited IEEE Transactions on Knowledge and Data Engineering (Volume:15 , Issue: 4 )
Memory blocks have fixed lengths ranging from a minimum to a maximum size in fixed increments, for example from 32 to 8192 bytes. Free blocks are managed in linked lists, one for each block size. The metadata of each block, such as the prev/next pointers (valid only if free) and the block size, are stored within the block itself (see list_header_t).
Coalescence of free blocks is implemented by using boundary tags, as suggested in the paper. While it adds more complexity to the algorithm, we have found it essential to maintain a robust behavior in terms of usable space over time.
| fixed_lists_mem_t::fixed_lists_mem_t | ( | size_t | bufsize = 8192 * 10240, |
| size_t | incr = 32, |
||
| size_t | max = 16384 |
||
| ) |
Initialize the buffer with all blocks of the maximum size
| fixed_lists_mem_t::~fixed_lists_mem_t | ( | ) |
|
private |
Adds a new free block (located at 'address') to the list of blocks with 'block_size'.
Allocate space for a record/object of size 'length'. The address and the actual block size are returned in 'slot'. If the slot is larger than the best fit (i.e., the smallest block size larger than 'length'), the block is split into one with size equal to the best fit, and the remaining part is readded to the lists as a smaller free block.
If there is no block available with the requested size, the method returns an invalid slot (containing a null pointer). The calles should then attempt to free more blocks before trying again.
| rc_t fixed_lists_mem_t::defrag | ( | ) |
WARNING: This defrag method assumes that all blocks were freed beforehand (e.g. the overlying heap is empty)
|
inlineprivate |
|
private |
Removes a block of a given size from its linked list. Here we do not care which block is returned, since the method is invoked inside the allocation method. Thus, the list head is always removed, allowing allocation to happen in constant time.
|
private |
Removes a free block from the middle of a linked lists. This version of the method is used by block coalescence, which transforms 2 or 3 free blocks into one of larger size. This requires removing the smaller blocks from their free lists using this method.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
1.8.12