Allocator of fixed-size blocks. More...
Go to the source code of this file.
Data Structures | |
| struct | tommy_allocator_struct |
| Allocator of fixed-size blocks. More... | |
Typedefs | |
| typedef struct tommy_allocator_struct | tommy_allocator |
| Allocator of fixed-size blocks. More... | |
Functions | |
| TOMMY_API void | tommy_allocator_init (tommy_allocator *alloc, tommy_size_t block_size, tommy_size_t align_size) |
| Initializes the allocator. More... | |
| TOMMY_API void | tommy_allocator_done (tommy_allocator *alloc) |
| Deinitializes the allocator. More... | |
| TOMMY_API void | tommy_allocator_clear (tommy_allocator *alloc) |
| Releases all the allocated memory to the heap, including blocks still in use. More... | |
| TOMMY_API void * | tommy_allocator_alloc (tommy_allocator *alloc) |
| Allocates a block. More... | |
| TOMMY_API void | tommy_allocator_free (tommy_allocator *alloc, void *ptr) |
| Deallocates a block. More... | |
| TOMMY_API tommy_size_t | tommy_allocator_memory_usage (const tommy_allocator *alloc) |
| Gets the total size of allocated blocks currently in use. More... | |
Allocator of fixed-size blocks.
| typedef struct tommy_allocator_struct tommy_allocator |
Allocator of fixed-size blocks.
| TOMMY_API void tommy_allocator_init | ( | tommy_allocator * | alloc, |
| tommy_size_t | block_size, | ||
| tommy_size_t | align_size | ||
| ) |
Initializes the allocator.
| alloc | The allocator. |
| block_size | Size of the block to allocate. |
| align_size | Minimum alignment requirement. Values smaller than sizeof(void*) are raised to sizeof(void*). After this adjustment, align_size must be a multiple of sizeof(void*) because allocator blocks store free-list pointers. |
| TOMMY_API void tommy_allocator_done | ( | tommy_allocator * | alloc | ) |
Deinitializes the allocator.
It also releases all the allocated memory to the heap.
| alloc | The allocator. |
| TOMMY_API void tommy_allocator_clear | ( | tommy_allocator * | alloc | ) |
Releases all the allocated memory to the heap, including blocks still in use.
All previously allocated block pointers become invalid and must not be used or freed. The allocator remains initialized and can be reused immediately with the same block size and alignment. Its memory usage becomes zero. Calling this function on an empty allocator has no effect.
| alloc | The allocator. |
| TOMMY_API void * tommy_allocator_alloc | ( | tommy_allocator * | alloc | ) |
Allocates a block.
| alloc | The allocator. |
| TOMMY_API void tommy_allocator_free | ( | tommy_allocator * | alloc, |
| void * | ptr | ||
| ) |
Deallocates a block.
You must use the same allocator used in the tommy_allocator_alloc() call.
| alloc | The allocator. |
| ptr | Block to free. |
| TOMMY_API tommy_size_t tommy_allocator_memory_usage | ( | const tommy_allocator * | alloc | ) |
Gets the total size of allocated blocks currently in use.
Excludes free blocks retained by the allocator and segment overhead.
| alloc | The allocator. |