nlib
|
A pool allocator that can allocate or free a fixed size of memory region in a lock free manner. More...
#include "nn/nlib/LockFree.h"
Public Member Functions | |
MemHolder * | Alloc () noexcept |
Allocates memory. This is thread-safe. More... | |
void | Free (MemHolder *p) noexcept |
Frees memory. This is thread-safe. More... | |
MemHolder * | AllocUnsafe () noexcept |
This function is similar to Alloc() , but not thread-safe. More... | |
void | FreeUnsafe (MemHolder *p) noexcept |
This function is similar to Free() , but not thread-safe. More... | |
void | SwapUnsafe (LockFreeUnitHeap &rhs) noexcept |
Swaps an object. This is not thread-safe. | |
Constructor, Destructor, and Initialization | |
LockFreeUnitHeap () noexcept | |
Instantiates the object with default parameters (default constructor). | |
errno_t | Init (size_t unit_size, size_t align, size_t count) noexcept |
Initializes an allocator. This is not thread-safe. More... | |
~LockFreeUnitHeap () noexcept | |
Destructor. | |
A pool allocator that can allocate or free a fixed size of memory region in a lock free manner.
malloc()
and free()
, LockFreeUnitHeap
can allocate or free memory without a possibility of threads to be blocked. Using this class may be considered when threads are not allowed to be blocked or a relatively large size of memory needs to be dynamically allocated or freed. kBlockCount
regions that can be allocated and the regions are allocated from kNumThread
threads. Definition at line 783 of file LockFree.h.
|
inlinenoexcept |
Allocates memory. This is thread-safe.
NULL
pointer when the allocation was successful.Get()
member function. The allocated region can be obtained by executing Get()
on the returned pointer to the object and obtaining the return value. Definition at line 800 of file LockFree.h.
|
inlinenoexcept |
This function is similar to Alloc()
, but not thread-safe.
NULL
pointer when the allocation was successful. Definition at line 811 of file LockFree.h.
|
inlinenoexcept |
Frees memory. This is thread-safe.
[in] | p | A return value of Alloc() . |
Definition at line 804 of file LockFree.h.
|
inlinenoexcept |
This function is similar to Free()
, but not thread-safe.
[in] | p | A return value of Alloc() . |
Definition at line 815 of file LockFree.h.
|
noexcept |
Initializes an allocator. This is not thread-safe.
[in] | unit_size | The size of each region to be allocated. |
[in] | align | The alignment of the region to be allocated. |
[in] | count | The maximum number of regions that can be allocated. |
0 | Success. |
ENOMEM | Memory allocation has failed. |
EINVAL | The alignment was not a power of two. |
© Nintendo Co., Ltd. All rights reserved.