nlib
nn::nlib::heap::UnitHeap Class Referencefinal

Heap for allocating and freeing fixed-size regions of memory. This is a so-called "pool-allocator.". More...

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

Public Types

typedef void(* DestructorHandler) (void *start, void *end)
 The type for functions called by the UnitHeap destructor.
 

Public Member Functions

errno_t Initialize (void *start, size_t size, DestructorHandler handler, size_t unit, size_t algn, uint32_t heap_option) noexcept
 Initializes a unit heap. More...
 
void * Alloc () noexcept
 Allocates a memory block. More...
 
errno_t Free (void *p) noexcept
 Returns memory to the heap. More...
 
size_t GetUnitSize () const noexcept
 Returns the size of each region that to be allocated from this heap. More...
 
size_t GetUnitCount () const noexcept
 Returns the number of regions that can be allocated from this heap. More...
 
size_t GetAllocatedCount () const noexcept
 Returns the number of regions that are currently allocated from this heap. More...
 
void Dump () noexcept
 Dumps the heap status.
 

Detailed Description

Heap for allocating and freeing fixed-size regions of memory. This is a so-called "pool-allocator.".

Definition at line 17 of file UnitHeap.h.

Member Function Documentation

nn::nlib::heap::UnitHeap::Alloc ( )
noexcept

Allocates a memory block.

Returns
Returns the pointer for the allocated memory. NULL if process fails.
nn::nlib::heap::UnitHeap::Free ( void *  p)
noexcept

Returns memory to the heap.

Parameters
[in]pSpecifies a pointer to the region to free.
Returns
Returns 0 on success. Any nonzero value indicates an invalid pointer.
nn::nlib::heap::UnitHeap::GetAllocatedCount ( ) const
inlinenoexcept

Returns the number of regions that are currently allocated from this heap.

Returns
Returns the number of regions that are currently allocated.

Definition at line 34 of file UnitHeap.h.

nn::nlib::heap::UnitHeap::GetUnitCount ( ) const
inlinenoexcept

Returns the number of regions that can be allocated from this heap.

Returns
Returns the number of regions that can be allocated from this heap.
Description
The current number of regions that can be allocated is GetUnitCount() - GetAllocatedCount().

Definition at line 33 of file UnitHeap.h.

nn::nlib::heap::UnitHeap::GetUnitSize ( ) const
inlinenoexcept

Returns the size of each region that to be allocated from this heap.

Returns
Returns the size of the region.

Definition at line 32 of file UnitHeap.h.

nn::nlib::heap::UnitHeap::Initialize ( void *  start,
size_t  size,
DestructorHandler  handler,
size_t  unit,
size_t  algn,
uint32_t  heap_option 
)
noexcept

Initializes a unit 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]unitSpecifies the size of each region to be allocated.
[in]algnSpecifies the alignment of the region.
[in]heap_optionThis value is not used.
Returns
Returns 0 if initialization succeeded, or any other value if initialization failed.
Description
Initialization of the free lists usually maintained the pool allocator is delayed until the memory is actually allocated and freed. As a result, initialization occurs relatively quickly even if a large amount of memory is provided to the heap.

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