3 #ifndef INCLUDE_NN_NLIB_HEAP_FRAMEHEAP_H_
4 #define INCLUDE_NN_NLIB_HEAP_FRAMEHEAP_H_
8 #if defined(_MSC_VER) && defined(nx_heap_EXPORTS)
10 #define NLIB_VIS_PUBLIC NLIB_WINEXPORT
18 typedef void (*DestructorHandler)(
void* start,
void* end);
20 ALLOCOPTION_ALLOCHEAD = 0x00000000,
21 ALLOCOPTION_ALLOCTAIL = 0x00000001
27 return _[0] == rhs._[0] && _[1] == rhs._[1];
30 return _[0] != rhs._[0] || _[1] != rhs._[1];
34 m_Cur.interlocked._[0] = m_Cur.interlocked._[1] = 0;
38 (*m_Handler)(m_Start, m_End);
41 errno_t Initialize(
void* start,
size_t size, DestructorHandler handler,
46 to.tb.botidx = m_End - m_Start;
49 void FreeTop() NLIB_NOEXCEPT { m_Cur.tb.topidx = 0; }
51 size_t bot = m_End - m_Start;
52 m_Cur.tb.botidx = bot;
59 void*
Alloc(
size_t n) NLIB_NOEXCEPT {
return this->
Alloc(n, 8, 0); }
60 void*
Alloc(
size_t n,
size_t algn) NLIB_NOEXCEPT {
return this->
Alloc(n, algn, 0); }
61 void* Alloc(
size_t n,
size_t algn, uint32_t alloc_option)
NLIB_NOEXCEPT;
62 void Dump() NLIB_NOEXCEPT;
72 static uint8_t* RoundUp(uint8_t* ptr,
size_t algn) NLIB_NOEXCEPT {
74 intptr_t tmp =
reinterpret_cast<intptr_t
>(ptr);
75 return reinterpret_cast<uint8_t*
>(tmp + (-tmp & (algn - 1)));
77 static uint8_t* RoundDown(uint8_t* ptr,
size_t algn)
NLIB_NOEXCEPT {
79 intptr_t tmp =
reinterpret_cast<intptr_t
>(ptr);
80 return reinterpret_cast<uint8_t*
>(tmp & (~algn + 1));
83 m_Start =
reinterpret_cast<uint8_t*
>(start);
84 m_End =
reinterpret_cast<uint8_t*
>(end);
90 uint32_t m_HeapOption;
93 DestructorHandler m_Handler;
99 #if defined(_MSC_VER) && defined(nx_heap_EXPORTS)
100 #undef NLIB_VIS_PUBLIC
101 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT
104 #endif // INCLUDE_NN_NLIB_HEAP_FRAMEHEAP_H_
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
bool operator==(const State &rhs) noexcept
Compares heap states and returns true if they are equal.
void FreeAll() noexcept
Frees all memory and restores the heap to its post-initialization state.
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
void FreeBot() noexcept
Frees all memory regions that were allocated from bottom of the heap.
void FreeTop() noexcept
Frees all memory regions that were allocated from top of the heap.
State SaveState() noexcept
Saves the current heap state.
Lists the state of the heap.
bool operator!=(const State &rhs) noexcept
Compares heap states and returns true if they are unequal.
Allows memory to be allocated from both sides of the heap.
void RestoreState(State state) noexcept
Restores a saved heap state.
A file that contains the configuration information for each development environment.
void * Alloc(size_t n, size_t algn) noexcept
Allocates a memory block with a specific alignment.
AllocOption
Specifies which side of the heap to allocate from.
void * Alloc(size_t n) noexcept
Allocates a memory block.