nlib
nn::nlib::heap::FrameHeap Class Referencefinal

Allows memory to be allocated from both sides of the heap. More...

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

Classes

struct  State
 Lists the state of the heap. More...
 

Public Types

enum  AllocOption {
  ALLOCOPTION_ALLOCHEAD = 0x00000000,
  ALLOCOPTION_ALLOCTAIL = 0x00000001
}
 Specifies which side of the heap to allocate from. More...
 
typedef void(* DestructorHandler) (void *start, void *end)
 The type for functions called by the FrameHeap destructor.
 

Public Member Functions

errno_t Init (void *start, size_t size, DestructorHandler handler, uint32_t heap_option) noexcept
 Initializes a frame heap. More...
 
void FreeAll () noexcept
 Frees all memory and restores the heap to its post-initialization state.
 
void FreeTop () noexcept
 Frees all memory regions that were allocated from top of the heap.
 
void FreeBot () noexcept
 Frees all memory regions that were allocated from bottom of the heap.
 
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. The function fails without truncating if memory has already been allocated from both sides. More...
 
State SaveState () noexcept
 Saves the current heap state. More...
 
void RestoreState (State state) noexcept
 Restores a saved heap state. More...
 
void * Alloc (size_t n) noexcept
 Allocates a memory block. More...
 
void * Alloc (size_t n, size_t algn) noexcept
 Allocates a memory block with a specific alignment. More...
 
void * Alloc (size_t n, size_t algn, uint32_t alloc_option) noexcept
 Allocates a memory block with a specific alignment and allocation options. More...
 
void Dump () noexcept
 Dumps the heap status.
 

Detailed Description

Allows memory to be allocated from both sides of the heap.

Definition at line 16 of file FrameHeap.h.

Member Enumeration Documentation

§ AllocOption

Specifies which side of the heap to allocate from.

Enumerator
ALLOCOPTION_ALLOCHEAD 

Allocates from the front of the heap.

ALLOCOPTION_ALLOCTAIL 

Allocates from the end of the heap.

Definition at line 19 of file FrameHeap.h.

Member Function Documentation

§ Adjust()

nn::nlib::heap::FrameHeap::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. The function fails without truncating if memory has already been allocated from both sides.

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.

§ Alloc() [1/3]

nn::nlib::heap::FrameHeap::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 59 of file FrameHeap.h.

§ Alloc() [2/3]

nn::nlib::heap::FrameHeap::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.

Definition at line 60 of file FrameHeap.h.

§ Alloc() [3/3]

nn::nlib::heap::FrameHeap::Alloc ( size_t  n,
size_t  algn,
uint32_t  alloc_option 
)
noexcept

Allocates a memory block with a specific alignment and allocation options.

Parameters
[in]nSpecifies the memory block size.
[in]algnSpecifies the alignment.
[in]alloc_optionSpecifies options during allocation (value of type AllocOption).
Returns
Returns the pointer for the allocated memory. NULL if process fails.

§ Init()

nn::nlib::heap::FrameHeap::Init ( void *  start,
size_t  size,
DestructorHandler  handler,
uint32_t  heap_option 
)
noexcept

Initializes a frame heap.

Parameters
[in]startSpecifies a pointer to the beginning of the heap.
[in]sizeSpecifies the size of the heap.
[in]handlerSpecifies a pointer to the function that is called when the destructor runs.
[in]heap_optionThis value is not used.
Returns
Returns 0 if initialization succeeded, or any other value if initialization failed.

§ ResizeTop()

nn::nlib::heap::FrameHeap::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.

§ RestoreState()

nn::nlib::heap::FrameHeap::RestoreState ( State  state)
inlinenoexcept

Restores a saved heap state.

Parameters
[in]stateSpecifies the state of the heap to be restored.

Definition at line 58 of file FrameHeap.h.

§ SaveState()

nn::nlib::heap::FrameHeap::SaveState ( )
inlinenoexcept

Saves the current heap state.

Returns
Saves the current memory allocation state of the heap.

Definition at line 57 of file FrameHeap.h.


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