Allocator that allocates memory from the top like a stack.
More...
#include "nn/nlib/heap/StackHeap.h"
|
errno_t | Init (void *start, size_t size, uint32_t heap_option) noexcept |
| Initializes the stack heap. More...
|
|
void | FreeAll () noexcept |
| Frees all memory and restores the heap to its post-initialization state.
|
|
errno_t | ResizeTop (void *p, size_t from_size, size_t to_size) noexcept |
| Changes the size of the most recently allocated memory. More...
|
|
errno_t | Adjust (void **start, size_t *size) noexcept |
| Truncates the size of the heap up so that it stops after the regions that have been allocated so far. More...
|
|
void * | Alloc (size_t n, size_t algn) noexcept |
| Allocates a memory block with a specific alignment. More...
|
|
void * | Alloc (size_t n) noexcept |
| Allocates a memory block. More...
|
|
errno_t | Free (void *p) noexcept |
| Moves the location of the next memory allocation back to the address that p points to. More...
|
|
void | Dump () noexcept |
| Dumps the heap status.
|
|
Allocator that allocates memory from the top like a stack.
- Description
- When using this allocator, allocations and deallocations must occur in LIFO (last in, first out) order.
Definition at line 16 of file StackHeap.h.
§ Adjust()
nn::nlib::heap::StackHeap::Adjust |
( |
void ** |
start, |
|
|
size_t * |
size |
|
) |
| |
|
noexcept |
Truncates the size of the heap up so that it stops after the regions that have been allocated so far.
- Parameters
-
[in] | start | Specifies a pointer to the start of the region to remove from the heap. |
[in] | size | Specifies the size of the region to remove from the heap. |
- Returns
- Returns
0
on success. Any other value indicates failure.
§ Alloc() [1/2]
nn::nlib::heap::StackHeap::Alloc |
( |
size_t |
n, |
|
|
size_t |
algn |
|
) |
| |
|
inlinenoexcept |
Allocates a memory block with a specific alignment.
- Parameters
-
[in] | n | Specifies the memory block size. |
[in] | algn | Specifies the alignment. |
- Returns
- Returns the pointer for the allocated memory.
NULL
if process fails.
- Description
- The alignment must be a power of two.
Definition at line 24 of file StackHeap.h.
§ Alloc() [2/2]
nn::nlib::heap::StackHeap::Alloc |
( |
size_t |
n | ) |
|
|
inlinenoexcept |
Allocates a memory block.
- Parameters
-
[in] | n | Specifies the memory block size. |
- Returns
- Returns the pointer for the allocated memory.
NULL
if process fails.
Definition at line 33 of file StackHeap.h.
§ Free()
nn::nlib::heap::StackHeap::Free |
( |
void * |
p | ) |
|
|
inlinenoexcept |
Moves the location of the next memory allocation back to the address that p points to.
- Parameters
-
[in] | p | Specifies a pointer to the memory block to free. |
- Returns
- Returns
0
on success. Any nonzero value indicates an invalid pointer.
Definition at line 34 of file StackHeap.h.
§ Init()
nn::nlib::heap::StackHeap::Init |
( |
void * |
start, |
|
|
size_t |
size, |
|
|
uint32_t |
heap_option |
|
) |
| |
|
noexcept |
Initializes the stack heap.
- Parameters
-
[in] | start | Specifies a pointer to the beginning of the heap. |
[in] | size | Specifies the size of the heap. |
[in] | heap_option | This value is not used. |
- Returns
- Returns
0
on success.
§ ResizeTop()
nn::nlib::heap::StackHeap::ResizeTop |
( |
void * |
p, |
|
|
size_t |
from_size, |
|
|
size_t |
to_size |
|
) |
| |
|
noexcept |
Changes the size of the most recently allocated memory.
- Parameters
-
[in] | p | Specifies the pointer to the most recently allocated memory. |
[in] | from_size | Specifies the original size. |
[in] | to_size | Specifies the desired size. |
- Returns
- Returns
0
on success. Any other value indicates failure.
The documentation for this class was generated from the following files: