Thread-specific cache class whose use is paired with CentralHeap
.
More...
#include "nn/nlib/heap/CachedHeap.h"
Thread-specific cache class whose use is paired with CentralHeap
.
- Description
- Used to implement
nmalloc
, which uses thread-local storage to maintain CachedHeap
objects for each thread.
- By preparing a
CachedHeap
object for each thread, and using CachedHeap
to handle the allocation and freeing of memory, the need for mutual exclusion can be reduced and the ability arises to allocate, or free, memory at high-speed in a multi-threaded environment. It is also possible to free and return memory that was allocated in CachedHeap
in one thread to the CachedHeap
in another thread, assuming the CentralHeap
is the same.
Definition at line 19 of file CachedHeap.h.
§ Alloc() [1/2]
nn::nlib::heap::CachedHeap::Alloc |
( |
size_t |
n | ) |
|
|
noexcept |
Allocates a memory region of the specified size (in bytes).
- Parameters
-
[in] | n | Size of the memory block to be allocated, in bytes. |
- Returns
- If successful, returns a pointer to the allocated memory block.
NULL
if process fails.
§ Alloc() [2/2]
nn::nlib::heap::CachedHeap::Alloc |
( |
size_t |
n, |
|
|
size_t |
algn |
|
) |
| |
|
noexcept |
Allocates memory with a specific alignment.
- Parameters
-
[in] | n | Size of the memory block to be allocated, in bytes. |
[in] | algn | Alignment of the memory block to allocate. |
- Returns
- If successful, returns a pointer to the allocated memory block.
NULL
if process fails.
- Description
- The value passed to algn must be a power of two that is less than or equal to
CentralHeap::kPageSize
.
§ CheckCache()
nn::nlib::heap::CachedHeap::CheckCache |
( |
| ) |
|
|
noexcept |
Checks the status of the cache.
- Returns
- Returns
true
if the cache is in a "normal" state.
§ Free()
nn::nlib::heap::CachedHeap::Free |
( |
void * |
p | ) |
|
|
noexcept |
Frees a memory region.
- Parameters
-
[in] | p | Specifies a pointer to the memory block to free. |
- Returns
- Returns
0
if the memory was freed without issue. Any other value indicates that an issue was detected (For example, p may never have been allocated).
§ FreeWithSize()
nn::nlib::heap::CachedHeap::FreeWithSize |
( |
void * |
p, |
|
|
size_t |
size |
|
) |
| |
|
noexcept |
Frees memory that was allocated with a specific size.
- Parameters
-
[in] | p | Specifies a pointer to the memory block to free. |
[in] | size | Specifies the size that was allocated to the p parameter. |
- Returns
- Returns
0
if the memory was freed without issue. Any other value indicates that an issue was detected (For example, p may never have been allocated).
§ Realloc()
nn::nlib::heap::CachedHeap::Realloc |
( |
void * |
ptr, |
|
|
size_t |
size, |
|
|
void ** |
p |
|
) |
| |
|
noexcept |
Reallocates the specified memory to have the specified size.
- Parameters
-
[in] | ptr | Specifies a pointer to the memory you want to reallocate. |
[in] | size | Specifies the size after changing (in bytes). |
[out] | p | Specifies a pointer to the reallocated memory. |
- Returns
- Returns
0
if memory reallocation was successful. Any other value indicates that an issue was detected (For example, ptr may never have been allocated).
- Description
- 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: