nlib
nn::nlib::heap::StackHeap Class Referencefinal

Allocator that allocates memory from the top like a stack. More...

#include "nn/nlib/heap/StackHeap.h"

Public Member Functions

errno_t Initialize (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.
 

Detailed Description

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.

Member Function Documentation

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]startSpecifies a pointer to the start of the region to remove from the heap.
[in]sizeSpecifies the size of the region to remove from the heap.
Returns
Returns 0 on success. Any other value indicates failure.
nn::nlib::heap::StackHeap::Alloc ( size_t  n,
size_t  algn 
)
inlinenoexcept

Allocates a memory block with a specific alignment.

Parameters
[in]nSpecifies the memory block size.
[in]algnSpecifies 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.

nn::nlib::heap::StackHeap::Alloc ( size_t  n)
inlinenoexcept

Allocates a memory block.

Parameters
[in]nSpecifies the memory block size.
Returns
Returns the pointer for the allocated memory. NULL if process fails.

Definition at line 33 of file StackHeap.h.

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]pSpecifies 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.

nn::nlib::heap::StackHeap::Initialize ( void *  start,
size_t  size,
uint32_t  heap_option 
)
noexcept

Initializes the stack heap.

Parameters
[in]startSpecifies a pointer to the beginning of the heap.
[in]sizeSpecifies the size of the heap.
[in]heap_optionThis value is not used.
Returns
Returns 0 on success.
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]pSpecifies the pointer to the most recently allocated memory.
[in]from_sizeSpecifies the original size.
[in]to_sizeSpecifies the desired size.
Returns
Returns 0 on success. Any other value indicates failure.

The documentation for this class was generated from the following files: