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