nlib
UnitHeap.h
[詳解]
1 
2 /*--------------------------------------------------------------------------------*
3  Project: CrossRoad
4  Copyright (C)Nintendo All rights reserved.
5 
6  These coded instructions, statements, and computer programs contain proprietary
7  information of Nintendo and/or its licensed developers and are protected by
8  national and international copyright laws. They may not be disclosed to third
9  parties or copied or duplicated in any form, in whole or in part, without the
10  prior written consent of Nintendo.
11 
12  The content herein is highly confidential and should be handled accordingly.
13  *--------------------------------------------------------------------------------*/
14 
15 #pragma once
16 #ifndef INCLUDE_NN_NLIB_HEAP_UNITHEAP_H_
17 #define INCLUDE_NN_NLIB_HEAP_UNITHEAP_H_
18 
19 #include "nn/nlib/Config.h"
20 
21 #if defined(_MSC_VER) && defined(nx_heap_EXPORTS)
22 #undef NLIB_VIS_PUBLIC
23 #define NLIB_VIS_PUBLIC NLIB_WINEXPORT
24 #endif
25 
26 NLIB_NAMESPACE_BEGIN
27 namespace heap {
28 
30  public:
31  typedef void (*DestructorHandler)(void* start, void* end) NLIB_NOEXCEPT_FUNCPTR;
34  // Do not assert by GetAllocatedCount().
35  // Allow deallote without destroy.
36  if (handler_) {
37  (*handler_)(start_, end_);
38  }
39  }
40  errno_t Init(void* start, size_t size, DestructorHandler handler, size_t unit,
41  size_t algn, uint32_t heap_option) NLIB_NOEXCEPT;
42  void* Alloc() NLIB_NOEXCEPT;
43  errno_t Free(void* p) NLIB_NOEXCEPT;
44  size_t GetUnitSize() const NLIB_NOEXCEPT { return unit_size_; }
45  size_t GetUnitCount() const NLIB_NOEXCEPT { return unit_count_; }
46  size_t GetAllocatedCount() const NLIB_NOEXCEPT { return allocated_count_; }
47  void Dump() NLIB_NOEXCEPT;
48 
49  private:
50  struct Node {
51  Node* next;
52  };
53 
54  size_t unit_size_;
55  size_t baseunit_count_;
56  Node* free_list_;
57  size_t unit_count_;
58  size_t allocated_count_;
59 
60  uint32_t heap_option_;
61  uint8_t* start_;
62  uint8_t* end_;
63  DestructorHandler handler_;
65 };
66 
67 } // namespace heap
68 NLIB_NAMESPACE_END
69 
70 #if defined(_MSC_VER) && defined(nx_heap_EXPORTS)
71 #undef NLIB_VIS_PUBLIC
72 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT
73 #endif
74 
75 #endif // INCLUDE_NN_NLIB_HEAP_UNITHEAP_H_
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
TypeName で指定されたクラスのコピーコンストラクタと代入演算子を禁止します。
Definition: Config.h:179
size_t GetUnitCount() const noexcept
このヒープからアロケートできる領域の個数を返します。
Definition: UnitHeap.h:45
固定メモリサイズの領域を確保・解放するためのヒープです。所謂プールアロケータです。 ...
Definition: UnitHeap.h:29
size_t GetAllocatedCount() const noexcept
現在このヒープから確保されている領域の個数を返します。
Definition: UnitHeap.h:46
#define NLIB_VIS_PUBLIC
関数やクラス等のシンボルをライブラリの外部に公開します。
Definition: Platform_unix.h:89
size_t GetUnitSize() const noexcept
このヒープからアロケートされる領域の1つあたりのサイズを返します。
Definition: UnitHeap.h:44
#define NLIB_NOEXCEPT
環境に合わせてnoexcept 又は同等の定義がされます。
Definition: Config.h:105
開発環境別の設定が書かれるファイルです。
#define NLIB_FINAL
利用可能であればfinalが定義されます。そうでない場合は空文字列です。
Definition: Config.h:245
int errno_t
intのtypedefで、戻り値としてPOSIXのエラー値を返すことを示します。
Definition: NMalloc.h:37