Heap for allocating and freeing fixed-size regions of memory. This is a so-called "pool-allocator.".
More...
#include "nn/nlib/heap/UnitHeap.h"
|
typedef void(* | DestructorHandler) (void *start, void *end) NLIB_NOEXCEPT_FUNCPTR |
| The type for functions called by the UnitHeap destructor.
|
|
|
errno_t | Init (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.
|
|
Heap for allocating and freeing fixed-size regions of memory. This is a so-called "pool-allocator.".
Definition at line 29 of file UnitHeap.h.
◆ Alloc()
nn::nlib::heap::UnitHeap::Alloc |
( |
| ) |
|
|
noexcept |
Allocates a memory block.
- Returns
- Returns the pointer for the allocated memory.
NULL
if process fails.
◆ Free()
nn::nlib::heap::UnitHeap::Free |
( |
void * |
p | ) |
|
|
noexcept |
Returns memory to the heap.
- Parameters
-
[in] | p | Specifies a pointer to the region to free. |
- Returns
- Returns
0
on success. Any nonzero value indicates an invalid pointer.
◆ GetAllocatedCount()
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 46 of file UnitHeap.h.
◆ GetUnitCount()
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 45 of file UnitHeap.h.
◆ GetUnitSize()
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 44 of file UnitHeap.h.
◆ Init()
nn::nlib::heap::UnitHeap::Init |
( |
void * |
start, |
|
|
size_t |
size, |
|
|
DestructorHandler |
handler, |
|
|
size_t |
unit, |
|
|
size_t |
algn, |
|
|
uint32_t |
heap_option |
|
) |
| |
|
noexcept |
Initializes a unit heap.
- Parameters
-
[in] | start | Specifies a pointer to the beginning of the heap. |
[in] | size | Specifies the size of the heap. |
[in] | handler | Specifies a pointer to the function that is called when the destructor runs. |
[in] | unit | Specifies the size of each region to be allocated. |
[in] | algn | Specifies the alignment of the region. |
[in] | heap_option | This 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 by the pool allocator is delayed until the memory is actually allocated and freed. Therefore, the initialization can be done within a relatively short time even if a large amount of memory is provided to the heap.
The documentation for this class was generated from the following files: