Central heap class whose use is paired with CachedHeap
. It is used to implement nmalloc
.
More...
#include "nn/nlib/heap/CentralHeap.h"
|
static const size_t | kPageSize |
| Page size of the heap (not related to the operating system page size).
|
|
Central heap class whose use is paired with CachedHeap
. It is used to implement nmalloc
.
- Description
- It can be used to create
CachedHeap
instances (thread-specific heaps). CachedHeap
allocates memory from and returns memory to the central heap. Memory allocation and freeing by user applications are generally performed using CachedHeap
. Memory can also be allocated directly from the CentralHeap
, however, this decreases efficiency.
Definition at line 31 of file CentralHeap.h.
◆ Alloc() [1/2]
nn::nlib::heap::CentralHeap::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 41 of file CentralHeap.h.
◆ Alloc() [2/2]
nn::nlib::heap::CentralHeap::Alloc |
( |
size_t |
n, |
|
|
size_t |
algn |
|
) |
| |
|
noexcept |
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.
- The alignment must be a power of two.
◆ Free()
nn::nlib::heap::CentralHeap::Free |
( |
void * |
p | ) |
|
|
noexcept |
Frees memory.
- Parameters
-
[in] | p | Specifies a pointer to the memory block to free. |
- Returns
- Returns
0
on success. Any nonzero value indicates that an error has occurred (for example, the pointer wasn't in the heap).
◆ FreeWithSize()
nn::nlib::heap::CentralHeap::FreeWithSize |
( |
void * |
p, |
|
|
size_t |
size |
|
) |
| |
|
noexcept |
Frees a memory region of an allocated size you specify.
- Parameters
-
[in] | p | A pointer to the memory block you want to free. |
[in] | size | The size that has been allocated to p. |
- Returns
- Returns
0
if the memory was successfully freed. Any other value indicates that an issue was detected (For example, p may never have been allocated).
◆ Init()
nn::nlib::heap::CentralHeap::Init |
( |
void * |
start, |
|
|
size_t |
size, |
|
|
uint32_t |
heap_option |
|
) |
| |
|
noexcept |
Initializes the heap.
- Parameters
-
[in] | start | Specifies a pointer to the beginning of the heap. |
[in] | size | Specifies the size of the heap. It must be a multiple of kPageSize . |
[in] | heap_option | Specifies the heap-instantiation options. See NMallocSettings::heap_option . |
- Returns
- 0 Indicates that initialization was successful. Any other return value indicates failure.
- Description
- If a start is not aligned to
kPageSize
, the region is truncated to the memory boundary before use.
◆ MakeCache()
nn::nlib::heap::CentralHeap::MakeCache |
( |
CachedHeap * |
ptr | ) |
|
|
noexcept |
Initializes CachedHeap
and associates it with this CentralHeap
.
- Parameters
-
[out] | ptr | Specifies a pointer to the CachedHeap object to initialize. |
- Returns
- Returns
true
on success.
- Description
- When this function is called, the central heap allocates a cache region and associates itself with
CachedHeap
. Thereafter, memory can be allocated and freed using CachedHeap
.
◆ Realloc()
nn::nlib::heap::CentralHeap::Realloc |
( |
void * |
ptr, |
|
|
size_t |
size, |
|
|
void ** |
p |
|
) |
| |
|
noexcept |
Reallocates the memory that has been allocated with its size specified.
- Parameters
-
[in] | ptr | A pointer to the memory you want to reallocate. |
[in] | size | The size, in bytes, after the change. |
[out] | p | A pointer to the reallocated memory. |
- Returns
- Returns
0
if the memory has been successfully reallocated. Any other value indicates that an issue was detected (For example, no memory has never been allocated for ptr).
- Description
- Note that, unlike the standard realloc function, the ptr parameter cannot be set to
NULL
, and the size parameter cannot be set to 0.
The documentation for this class was generated from the following files: