#include <smba.h>
Classes | |
struct | tag_Page |
Public Member Functions | |
void * | alloc (unsigned int bytes) |
Allocates a small block wide at least bytes. | |
void | free (void *bytes) |
Frees the given memory block. | |
SmallMemBlockAlloc () | |
~SmallMemBlockAlloc () | |
Protected Types | |
enum | { page_list_size = 4 } |
typedef struct Falcon::SmallMemBlockAlloc::tag_Page | PAGE_HEADER |
Protected Member Functions | |
PAGE_HEADER * | newPage (int blockSize) |
Protected Attributes | |
Mutex * | m_mtx |
void * | page_free_lists [page_list_size] |
List of free pointers, organized for block size. | |
PAGE_HEADER * | page_lists [page_list_size] |
Pages, organized for block size. |
This is an optimized allocator which works with fixed size small memory blocks: 8, 16, 32 and 64 bytes respectively, without memory overhead for accounting.
The allocator manages directly heap pages and is able to determine the size of the allocated block by getting the address of the page from which it came from.
This allocator is useful to account very small data as the trie memory blocks, but can be cool also to store small strings, item references and all those things for which you may want a lightning fast memory allocator and zero memory overhead.
The engine provides a single SMBA for all the falcon.
typedef struct Falcon::SmallMemBlockAlloc::tag_Page Falcon::SmallMemBlockAlloc::PAGE_HEADER [protected] |
Falcon::SmallMemBlockAlloc::SmallMemBlockAlloc | ( | ) |
Falcon::SmallMemBlockAlloc::~SmallMemBlockAlloc | ( | ) |
void* Falcon::SmallMemBlockAlloc::alloc | ( | unsigned int | bytes | ) |
Allocates a small block wide at least bytes.
If the requested memory size is greater than the maximum size managed by this memory manager, function returns 0.
bytes | Quantity of memory required. |
void Falcon::SmallMemBlockAlloc::free | ( | void * | bytes | ) |
Frees the given memory block.
The | memory block to be freed. |
PAGE_HEADER* Falcon::SmallMemBlockAlloc::newPage | ( | int | blockSize | ) | [protected] |
Mutex* Falcon::SmallMemBlockAlloc::m_mtx [protected] |
void* Falcon::SmallMemBlockAlloc::page_free_lists[page_list_size] [protected] |
List of free pointers, organized for block size.
PAGE_HEADER* Falcon::SmallMemBlockAlloc::page_lists[page_list_size] [protected] |
Pages, organized for block size.