Go to the source code of this file.
◆ arena_alloc
Allocate a chunk of memory from the arena.
Through pushing the commit position of arena, and returning the allocated chunk that you specify, the reason for it being a macro is due to being able to specify the type, this will automatically grow the commit size if it's too small, all this logic resides in __arena_alloc().
- Parameters
-
| arena | The arena to allocate from. |
| type | The type of the chunk to allocate. |
| size | The size of the chunk to allocate. |
- Precondition
arena, type, and size must be valid and cannot be null.
type must be a valid type.
- Returns
- A pointer to the allocated chunk.
- See also
- __arena_alloc()
◆ arena_dealloc
Deallocate a chunk of memory from the arena.
Through popping the position from the arena, using __arena_dealloc(), the reason this is a macro is to be able to pass type.
- Parameters
-
| arena | The arena to deallocate from. |
| type | The type of the chunk to deallocate. |
| size | The size of the chunk to deallocate. |
- Precondition
arena, type, and size must be valid and cannot be null.
type must be a valid type.
- See also
- __arena_dealloc()
◆ GiB
| #define GiB |
( |
|
bytes | ) |
((u64)bytes << 30) |
◆ KiB
| #define KiB |
( |
|
bytes | ) |
((u64)bytes << 10) |
◆ MiB
| #define MiB |
( |
|
bytes | ) |
((u64)bytes << 20) |
◆ arena_t
An arena.
- Parameters
-
| reserved | The size of the arena. |
| committed | The size of the committed heap. |
| pos | The current position of the heap. |
| commit_pos | The current position of the committed heap. |
◆ temp_arena_t
A temporary arena.
- Parameters
-
| arena | The arena to create the temporary arena from. |
| start_pos | The position to start the temporary arena from. |
◆ __arena_alloc()
| void * __arena_alloc |
( |
struct arena * |
arena, |
|
|
u64 |
size |
|
) |
| |
Allocate a chunk of memory to the arena.
- Note
- This function is not meant to be run directly, and is called by the arena_alloc() macro.
Through basically pushing the position forwards and returning a small chunk of memory from the committed heap.
- Parameters
-
| arena | The arena to allocate from. |
| size | The size of the chunk to allocate. |
- Precondition
arena and size must be valid and cannot be null.
size must be greater than 0.
- Returns
- A pointer to the allocated chunk.
- See also
- arena_alloc()
◆ __arena_dealloc()
| void __arena_dealloc |
( |
struct arena * |
arena, |
|
|
u64 |
size |
|
) |
| |
Deallocate a chunk of memory from the arena.
- Note
- This function is not meant to be run directly, and is called by the arena_dealloc() macro.
Through basically popping back the position, so that it may be reused for other allocations.
- Parameters
-
| arena | The arena to deallocate from. |
| size | The size of the chunk to deallocate. |
- Precondition
arena and size must be valid and cannot be null.
size must be greater than 0.
- See also
- arena_dealloc()
◆ arena_clear()
| void arena_clear |
( |
arena_t * |
arena | ) |
|
Clear the arena.
Pops the arena to the base position of ARENA_BASE_POS using arena_dealloc_to(), then flushes the commit position using mem_decommit() and mem_commit().
- Parameters
-
- Precondition
arena must be valid and cannot be null.
- See also
- arena_dealloc_to()
◆ arena_dealloc_to()
| void arena_dealloc_to |
( |
arena_t * |
arena, |
|
|
u64 |
pos |
|
) |
| |
Set arena position to @pos.
Through setting the position of the arena to pos, useful for clearing or removing a chunk of data you know you dont need any more. Uses __arena_dealloc() internally.
- Parameters
-
| arena | The arena to deallocate from. |
| pos | The position to deallocate to. |
- Precondition
arena and pos must be valid and cannot be null.
pos must be greater than 0.
- See also
- __arena_dealloc()
◆ arena_free()
Free an arena.
Frees an arena using munmap() or VirtualFree(), depending on system, this is rarely needed cause the kernel usually frees these pages for you, but its useful if you use multiple arenas..
- Parameters
-
- Precondition
arena must be valid and cannot be null.
- See also
- munmap(), VirtualFree()
◆ arena_new()
Create a new arena.
Initializes a new arena using mmap() or VirtualAlloc(), depending on system.
- Parameters
-
| reserve_size | The size of the arena to reserve. |
| commit_size | The size of the arena to commit. |
- Precondition
reserve_size must be greater than 0.
commit_size must be greater than 0 and less than or equal to reserve_size.
- Returns
- A pointer to the new arena.
- See also
- mmap(), VirtualAlloc()
◆ temp_arena_free()
◆ temp_arena_new()