Contains the implementation of the dynamic allocator.
More...
Go to the source code of this file.
|
KAPI b8 | dynamic_allocator_create (u64 total_size, u64 *memory_requirement, void *memory, dynamic_allocator *out_allocator) |
| Creates a new dynamic allocator. Should be called twice; once to obtain the memory amount required (passing memory=0), and a second time with memory being set to an allocated block. More...
|
|
KAPI b8 | dynamic_allocator_destroy (dynamic_allocator *allocator) |
| Destroys the given allocator. More...
|
|
KAPI void * | dynamic_allocator_allocate (dynamic_allocator *allocator, u64 size) |
| Allocates the given amount of memory from the provided allocator. More...
|
|
KAPI void * | dynamic_allocator_allocate_aligned (dynamic_allocator *allocator, u64 size, u16 alignment) |
| Allocates the given amount of aligned memory from the provided allocator. More...
|
|
KAPI b8 | dynamic_allocator_free (dynamic_allocator *allocator, void *block, u64 size) |
| Frees the given block of memory. More...
|
|
KAPI b8 | dynamic_allocator_free_aligned (dynamic_allocator *allocator, void *block) |
| Frees the given block of aligned memory. Technically the same as calling dynamic_allocator_free, but here for API consistency. No size is required. More...
|
|
KAPI b8 | dynamic_allocator_get_size_alignment (void *block, u64 *out_size, u16 *out_alignment) |
| Obtains the size and alignment of the given block of memory. Can fail if invalid data is passed. More...
|
|
KAPI u64 | dynamic_allocator_free_space (dynamic_allocator *allocator) |
| Obtains the amount of free space left in the provided allocator. More...
|
|
KAPI u64 | dynamic_allocator_total_space (dynamic_allocator *allocator) |
| Obtains the amount of total space originally available in the provided allocator. More...
|
|
KAPI u64 | dynamic_allocator_header_size (void) |
|
Contains the implementation of the dynamic allocator.
- Author
- Travis Vroman (travi.nosp@m.s@ko.nosp@m.hieng.nosp@m.ine..nosp@m.com)
- Version
- 1.0
- Date
- 2022-01-25
- Copyright
- Kohi Game Engine is Copyright (c) Travis Vroman 2021-2022
◆ dynamic_allocator
The dynamic allocator structure.
◆ dynamic_allocator_allocate()
Allocates the given amount of memory from the provided allocator.
- Parameters
-
allocator | A pointer to the allocator to allocate from. |
size | The amount in bytes to be allocated. |
- Returns
- The allocated block of memory unless this operation fails, then 0.
◆ dynamic_allocator_allocate_aligned()
Allocates the given amount of aligned memory from the provided allocator.
- Parameters
-
allocator | A pointer to the allocator to allocate from. |
size | The amount in bytes to be allocated. |
alignment | The alignment in bytes. |
- Returns
- The aligned, allocated block of memory unless this operation fails, then 0.
◆ dynamic_allocator_create()
Creates a new dynamic allocator. Should be called twice; once to obtain the memory amount required (passing memory=0), and a second time with memory being set to an allocated block.
- Parameters
-
total_size | The total size in bytes the allocator should hold. Note this size does not include the size of the internal state. |
memory_requirement | A pointer to hold the required memory for the internal state plus total_size. |
memory | An allocated block of memory, or 0 if just obtaining the requirement. |
out_allocator | A pointer to hold the allocator. |
- Returns
- True on success; otherwise false.
◆ dynamic_allocator_destroy()
Destroys the given allocator.
- Parameters
-
allocator | A pointer to the allocator to be destroyed. |
- Returns
- True on success; otherwise false.
◆ dynamic_allocator_free()
Frees the given block of memory.
- Parameters
-
allocator | A pointer to the allocator to free from. |
block | The block to be freed. Must have been allocated by the provided allocator. |
size | The size of the block. |
- Returns
- True on success; otherwise false.
◆ dynamic_allocator_free_aligned()
Frees the given block of aligned memory. Technically the same as calling dynamic_allocator_free, but here for API consistency. No size is required.
- Parameters
-
allocator | A pointer to the allocator to free from. |
block | The block to be freed. Must have been allocated by the provided allocator. |
- Returns
- True on success; otherwise false.
◆ dynamic_allocator_free_space()
Obtains the amount of free space left in the provided allocator.
- Parameters
-
allocator | A pointer to the allocator to be examined. |
- Returns
- The amount of free space in bytes.
◆ dynamic_allocator_get_size_alignment()
KAPI b8 dynamic_allocator_get_size_alignment |
( |
void * |
block, |
|
|
u64 * |
out_size, |
|
|
u16 * |
out_alignment |
|
) |
| |
Obtains the size and alignment of the given block of memory. Can fail if invalid data is passed.
- Parameters
-
block | The block of memory. |
out_size | A pointer to hold the size. |
out_alignment | A pointer to hold the alignment. |
- Returns
- True on success; otherwise false.
◆ dynamic_allocator_header_size()
KAPI u64 dynamic_allocator_header_size |
( |
void |
| ) |
|
Obtains the size of the internal allocation header. This is really only used for unit testing purposes.
◆ dynamic_allocator_total_space()
Obtains the amount of total space originally available in the provided allocator.
- Parameters
-
allocator | A pointer to the allocator to be examined. |
- Returns
- The total amount of space originally available in bytes.