16 #ifndef INCLUDE_NN_NLIB_HEAP_STACKHEAP_H_ 17 #define INCLUDE_NN_NLIB_HEAP_STACKHEAP_H_ 21 #if defined(_MSC_VER) && defined(nx_heap_EXPORTS) 22 #undef NLIB_VIS_PUBLIC 23 #define NLIB_VIS_PUBLIC NLIB_WINEXPORT 41 if (n == 0)
return nullptr;
42 if (algn == 0 || 0 != (algn & (algn - 1)))
return nullptr;
43 uint8_t* ret = this->RoundUp(cur_, algn);
44 uint8_t* new_top = ret + n;
45 if (new_top > end_)
return nullptr;
51 uint8_t* ptr =
static_cast<uint8_t*
>(p);
52 if (ptr >= start_ && ptr < cur_) {
62 static uint8_t* RoundUp(uint8_t* ptr,
size_t algn)
NLIB_NOEXCEPT {
64 intptr_t tmp =
reinterpret_cast<intptr_t
>(ptr);
65 return reinterpret_cast<uint8_t*
>(tmp + (-tmp & (algn - 1)));
68 start_ =
static_cast<uint8_t*
>(start);
69 end_ =
static_cast<uint8_t*
>(end);
75 uint32_t heap_option_;
84 #if defined(_MSC_VER) && defined(nx_heap_EXPORTS) 85 #undef NLIB_VIS_PUBLIC 86 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT 89 #endif // INCLUDE_NN_NLIB_HEAP_STACKHEAP_H_ Allocator that allocates memory from the top like a stack.
void * Alloc(size_t n) noexcept
Allocates a memory block.
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
Prohibits use of the copy constructor and assignment operator for the class specified by TypeName...
void * Alloc(size_t n, size_t algn) noexcept
Allocates a memory block with a specific alignment.
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
errno_t Free(void *p) noexcept
Moves the location of the next memory allocation back to the address that p points to...
#define NLIB_CEXPR
Defines constexpr if it is available for use. If not, holds an empty string.
A file that contains the configuration information for each development environment.
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
void FreeAll() noexcept
Frees all memory and restores the heap to its post-initialization state.