16 #ifndef INCLUDE_NN_NLIB_HEAP_FRAMEHEAP_H_ 17 #define INCLUDE_NN_NLIB_HEAP_FRAMEHEAP_H_ 21 #if defined(_MSC_VER) && defined(nx_heap_EXPORTS) 22 #undef NLIB_VIS_PUBLIC 23 #define NLIB_VIS_PUBLIC NLIB_WINEXPORT 31 typedef void (*DestructorHandler)(
void* start,
void* end) NLIB_NOEXCEPT_FUNCPTR;
32 enum AllocOption { kAllocOptionAllocHead = 0x00000000, kAllocOptionAllocTail = 0x00000001 };
37 return _[0] == rhs._[0] && _[1] == rhs._[1];
40 return _[0] != rhs._[0] || _[1] != rhs._[1];
44 cur_.interlocked._[0] = cur_.interlocked._[1] = 0;
48 (*handler_)(start_, end_);
52 Init(
void* start,
size_t size, DestructorHandler handler, uint32_t heap_option)
NLIB_NOEXCEPT;
56 to.tb.botidx = end_ - start_;
61 size_t bot = end_ - start_;
71 void* Alloc(
size_t n,
size_t algn, uint32_t alloc_option)
NLIB_NOEXCEPT;
82 static uint8_t* RoundUp(uint8_t* ptr,
size_t algn)
NLIB_NOEXCEPT {
84 intptr_t tmp =
reinterpret_cast<intptr_t
>(ptr);
85 return reinterpret_cast<uint8_t*
>(tmp + (-tmp & (algn - 1)));
87 static uint8_t* RoundDown(uint8_t* ptr,
size_t algn)
NLIB_NOEXCEPT {
89 intptr_t tmp =
reinterpret_cast<intptr_t
>(ptr);
90 return reinterpret_cast<uint8_t*
>(tmp & (~algn + 1));
93 start_ =
static_cast<uint8_t*
>(start);
94 end_ =
static_cast<uint8_t*
>(end);
99 uint32_t heap_option_;
102 DestructorHandler handler_;
109 #if defined(_MSC_VER) && defined(nx_heap_EXPORTS) 110 #undef NLIB_VIS_PUBLIC 111 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT 114 #endif // INCLUDE_NN_NLIB_HEAP_FRAMEHEAP_H_ bool operator==(const State &rhs) noexcept
ヒープの状態を比較して、等価ならばtrueを返します。
void FreeAll() noexcept
メモリを全て解放し、ヒープを初期化直後の状態に戻します。
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
TypeName で指定されたクラスのコピーコンストラクタと代入演算子を禁止します。
void FreeBot() noexcept
ヒープの下部から確保したメモリを全て解放します。
void FreeTop() noexcept
ヒープの上部から確保したメモリを全て解放します。
State SaveState() noexcept
現在のヒープの状態をセーブします。
bool operator!=(const State &rhs) noexcept
ヒープの状態を比較して、等価でなければtrueを返します。
void RestoreState(State state) noexcept
セーブしたヒープの状態に戻します。
#define NLIB_NOEXCEPT
環境に合わせてnoexcept 又は同等の定義がされます。
void * Alloc(size_t n, size_t algn) noexcept
アライメントを指定してメモリブロックを確保します。
AllocOption
アロケートをヒープのどちらがわから行うかを指定します。
#define NLIB_FINAL
利用可能であればfinalが定義されます。そうでない場合は空文字列です。
void * Alloc(size_t n) noexcept
メモリブロックを確保します。