nlib
UnitHeap.h
[詳解]
1 
2 #pragma once
3 #ifndef INCLUDE_NN_NLIB_HEAP_UNITHEAP_H_
4 #define INCLUDE_NN_NLIB_HEAP_UNITHEAP_H_
5 
6 #include "nn/nlib/Config.h"
8 
9 #if defined(_MSC_VER) && defined(nx_heap_EXPORTS)
10 #undef NLIB_VIS_PUBLIC
11 #define NLIB_VIS_PUBLIC NLIB_WINEXPORT
12 #endif
13 
14 NLIB_NAMESPACE_BEGIN
15 namespace heap {
16 
18  public:
19  typedef void (*DestructorHandler)(void* start, void* end);
22  // Do not assert by GetAllocatedCount().
23  // Allow deallote without destroy.
24  if (m_Handler) {
25  (*m_Handler)(m_Start, m_End);
26  }
27  }
28  errno_t Initialize(void* start, size_t size, DestructorHandler handler, size_t unit,
29  size_t algn, uint32_t heap_option) NLIB_NOEXCEPT;
30  void* Alloc() NLIB_NOEXCEPT;
31  errno_t Free(void* p) NLIB_NOEXCEPT;
32  size_t GetUnitSize() const NLIB_NOEXCEPT { return m_UnitSize; }
33  size_t GetUnitCount() const NLIB_NOEXCEPT { return m_UnitCount; }
34  size_t GetAllocatedCount() const NLIB_NOEXCEPT { return m_AllocatedCount; }
35  void Dump() NLIB_NOEXCEPT;
36 
37  private:
38  struct Node {
39  Node* next;
40  };
41 
42  size_t m_UnitSize;
43  size_t m_BaseUnitCount;
44  Node* m_FreeList;
45  size_t m_UnitCount;
46  size_t m_AllocatedCount;
47 
48  uint32_t m_HeapOption;
49  uint8_t* m_Start;
50  uint8_t* m_End;
51  DestructorHandler m_Handler;
52 };
53 
54 } // namespace heap
55 NLIB_NAMESPACE_END
56 
57 #if defined(_MSC_VER) && defined(nx_heap_EXPORTS)
58 #undef NLIB_VIS_PUBLIC
59 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT
60 #endif
61 
62 #endif // INCLUDE_NN_NLIB_HEAP_UNITHEAP_H_
#define NLIB_NOEXCEPT
環境に合わせてnoexcept 又は同等の定義がされます。
Definition: Platform.h:2151
#define NLIB_FINAL
利用可能であればfinalが定義されます。そうでない場合は空文字列です。
固定メモリサイズの領域を確保・解放するためのヒープです。所謂プールアロケータです。 ...
Definition: UnitHeap.h:17
size_t GetUnitCount() const noexcept
このヒープからアロケートできる領域の個数を返します。
Definition: UnitHeap.h:33
size_t GetAllocatedCount() const noexcept
現在このヒープから確保されている領域の個数を返します。
Definition: UnitHeap.h:34
開発環境別の設定が書かれるファイルです。
アラインされたメモリを得たい場合に利用します。
#define NLIB_VIS_PUBLIC
関数やクラス等のシンボルをライブラリの外部に公開します。
Definition: Platform_unix.h:51
int errno_t
intのtypedefで、戻り値としてPOSIXのエラー値を返すことを示します。
Definition: NMalloc.h:24