nlib
|
Thread-specific cache class whose use is paired with CentralHeap
.
More...
#include "nn/nlib/heap/CachedHeap.h"
Public Member Functions | |
void * | Alloc (size_t n) noexcept |
Allocates a memory region of the specified size (in bytes). More... | |
void * | Alloc (size_t n, size_t algn) noexcept |
Allocates memory with a specific alignment. More... | |
size_t | GetAllocSize (const void *p) noexcept |
Returns the size of memory actually allocated for the p parameter. | |
errno_t | Free (void *p) noexcept |
Frees a memory region. More... | |
errno_t | FreeWithSize (void *p, size_t size) noexcept |
Frees memory that was allocated with a specific size. More... | |
errno_t | Realloc (void *ptr, size_t size, void **p) noexcept |
Reallocates the specified memory to have the specified size. More... | |
Basic Member Functions | |
CachedHeap () noexcept | |
Instantiates the object with default parameters (default constructor). | |
~CachedHeap () noexcept | |
Destructor. Calls Finalize . | |
CachedHeap & | assign (CachedHeap &rhs, move_tag) |
Assigns the object by using swap for a move. | |
CachedHeap (CachedHeap &rhs, move_tag) | |
Instantiates the object by using swap for a move. | |
CachedHeap (CachedHeap &&rhs) | |
Instantiates the object (move constructor). This function is useful when using C++11. | |
CachedHeap & | operator= (CachedHeap &&rhs) |
Move assignment operator. This function is useful when using C++11. | |
void | swap (CachedHeap &rhs) noexcept |
Swaps the contents of an object. | |
Adding Metadata to Allocated Memory | |
Some | |
errno_t | SetMark1 (void *ptr, uint16_t mark1) noexcept |
Adds data to allocated memory. More... | |
errno_t | SetMark2 (void *ptr, uint16_t mark2) noexcept |
Adds data to allocated memory. More... | |
errno_t | GetMark (const void *ptr, uint16_t *mark1, uint16_t *mark2) noexcept |
Gets data that was added to allocated memory. More... | |
void * | GetObjPtr (void *raw_ptr) noexcept |
Gets an object pointer from a pointer recognized by CentralHeap . More... | |
CachedHeap Initialization and Finalization | |
Use | |
void | ReleaseAllCache () noexcept |
Corresponds to nmalloc_clear_tls . | |
void | Finalize () noexcept |
Corresponds to nmalloc_finalize_tls . | |
Error Checking | |
bool | CheckCache () noexcept |
Checks the status of the cache. More... | |
operator bool () const | |
Returns true if the cache was initialized using CentralHeap::MakeCache . | |
Thread-specific cache class whose use is paired with CentralHeap
.
nmalloc
, which uses thread-local storage to maintain CachedHeap
objects for each thread. 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.
|
noexcept |
Allocates a memory region of the specified size (in bytes).
[in] | n | Size of the memory block to be allocated, in bytes. |
NULL
if process fails.
|
noexcept |
Allocates memory with a specific alignment.
[in] | n | Size of the memory block to be allocated, in bytes. |
[in] | algn | Alignment of the memory block to allocate. |
NULL
if process fails.CentralHeap::kPageSize
.
|
noexcept |
Checks the status of the cache.
true
if the cache is in a "normal" state.
|
noexcept |
Frees a memory region.
[in] | p | Specifies a pointer to the memory block to free. |
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).
|
noexcept |
Frees memory that was allocated with a specific size.
[in] | p | Specifies a pointer to the memory block to free. |
[in] | size | Specifies the size that was allocated to the p parameter. |
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).
|
noexcept |
Gets data that was added to allocated memory.
[in] | ptr | Specifies a pointer to an allocated object. |
[out] | mark1 | Pointer to the location storing the first piece of 16-bit additional data. Can specify NULL . |
[out] | mark2 | Pointer to the location storing the second piece of 16-bit additional data. Can specify NULL . |
0 | Success. |
EINVAL | When ptr was NULL . |
EFAULT | Corrupted data was detected. |
Specified Option | Behavior |
---|---|
NMALLOC_HEAPOPTION_CHECK_0 | Sets mark1 and mark2 to 0 . |
NMALLOC_HEAPOPTION_CHECK_1 | Sets mark1 and mark2 to the additional data that was set. |
|
noexcept |
Gets an object pointer from a pointer recognized by CentralHeap
.
[in] | raw_ptr | Specifies a pointer recognized by CentralHeap. |
Specified Option | Behavior |
---|---|
NMALLOC_HEAPOPTION_CHECK_0 | Same pointer as raw_ptr. |
NMALLOC_HEAPOPTION_CHECK_1 | Object pointer. |
|
noexcept |
Reallocates the specified memory to have the specified size.
[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. |
0
if memory reallocation was successful. Any other value indicates that an issue was detected (For example, ptr may never have been allocated).realloc
function, the ptr parameter cannot be set to NULL
, and the size parameter cannot be set to 0
.
|
noexcept |
Adds data to allocated memory.
[in] | ptr | Specifies a pointer to an allocated object. |
[in] | mark1 | Specifies the first piece of 16-bit additional data. |
0 | Success. |
EINVAL | When ptr was NULL . |
Specified Option | Behavior |
---|---|
NMALLOC_HEAPOPTION_CHECK_0 | Returns 0 without doing anything. |
NMALLOC_HEAPOPTION_CHECK_1 | Sets additional data. |
|
noexcept |
Adds data to allocated memory.
[in] | ptr | Specifies a pointer to an allocated object. |
[in] | mark2 | Specifies the second piece of 16-bit additional data. |
0 | Success. |
EINVAL | When ptr was NULL . |
EFAULT | Corrupted data was detected. |
Specified Option | Behavior |
---|---|
NMALLOC_HEAPOPTION_CHECK_0 | Returns 0 without doing anything. |
NMALLOC_HEAPOPTION_CHECK_1 | Sets additional data. |
© 2013, 2014, 2015 Nintendo Co., Ltd. All rights reserved.