nlib
CentralHeap.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_CENTRALHEAP_H_
17 #define INCLUDE_NN_NLIB_HEAP_CENTRALHEAP_H_
18 
19 #include "nn/nlib/heap/NMalloc.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 
29 class CachedHeap;
30 class TlsHeapCentral;
32  public:
33  typedef void (*DestructorHandler)(void* start, void* end) NLIB_NOEXCEPT_FUNCPTR;
34 
36  : central_(nullptr), use_virtual_memory_(false), heap_option_(0),
37  start_(nullptr), end_(nullptr) {}
38  ~CentralHeap() NLIB_NOEXCEPT { this->Finalize(); }
39  errno_t Init(void* start, size_t size, uint32_t heap_option) NLIB_NOEXCEPT;
40  void Finalize() NLIB_NOEXCEPT;
41  NLIB_ALWAYS_INLINE void* Alloc(size_t n) NLIB_NOEXCEPT { return this->Alloc(n, 8); }
42  void* Alloc(size_t n, size_t algn) NLIB_NOEXCEPT;
43  errno_t Free(void* p) NLIB_NOEXCEPT;
44  errno_t FreeWithSize(void* p, size_t size) NLIB_NOEXCEPT;
45  size_t GetAllocSize(const void* p) NLIB_NOEXCEPT;
46  errno_t Realloc(void* ptr, size_t size, void** p) NLIB_NOEXCEPT;
47 
48  bool MakeCache(CachedHeap* ptr) NLIB_NOEXCEPT;
49  errno_t WalkAllocatedPtrs(nmalloc_heapwalk_callback func, void* user_ptr) NLIB_NOEXCEPT;
50  errno_t QueryV(int query, va_list ap) NLIB_NOEXCEPT;
51  errno_t Query(int query, ...) NLIB_NOEXCEPT;
52  static const size_t kPageSize;
53 
54  private:
55  TlsHeapCentral* central_;
56  bool use_virtual_memory_;
57  uint32_t heap_option_;
58  uint8_t* start_;
59  uint8_t* end_;
61 };
62 
63 } // namespace heap
64 NLIB_NAMESPACE_END
65 
66 #if defined(_MSC_VER) && defined(nx_heap_EXPORTS)
67 #undef NLIB_VIS_PUBLIC
68 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT
69 #endif
70 
71 #endif // INCLUDE_NN_NLIB_HEAP_CENTRALHEAP_H_
int(* nmalloc_heapwalk_callback)(void *allocated_ptr, size_t size, void *user_ptr)
nmalloc_walk_allocated_ptrs()から呼び出されるユーザー定義のコールバック関数です。 ...
Definition: NMalloc.h:125
#define NLIB_ALWAYS_INLINE
コンパイラに関数をインライン展開するように強く示します。
Definition: Platform_unix.h:97
constexpr CentralHeap() noexcept
デフォルトコンストラクタです。
Definition: CentralHeap.h:35
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
TypeName で指定されたクラスのコピーコンストラクタと代入演算子を禁止します。
Definition: Config.h:179
nmalloc/nfree等が宣言されているファイルです。
~CentralHeap() noexcept
デストラクタです。
Definition: CentralHeap.h:38
static const size_t kPageSize
ヒープのページサイズです(OSのページサイズとの関連性はありません)。
Definition: CentralHeap.h:52
CachedHeapと対になって利用される中央ヒープクラスです。nmalloc()の実装に利用されています。 ...
Definition: CentralHeap.h:31
#define NLIB_VIS_PUBLIC
関数やクラス等のシンボルをライブラリの外部に公開します。
Definition: Platform_unix.h:89
void * Alloc(size_t n) noexcept
メモリブロックを確保します。
Definition: CentralHeap.h:41
#define NLIB_NOEXCEPT
環境に合わせてnoexcept 又は同等の定義がされます。
Definition: Config.h:105
#define NLIB_CEXPR
利用可能であればconstexprが定義されます。そうでない場合は空文字列です。
Definition: Config.h:107
CentralHeapと対になって利用されるスレッド専用キャッシュクラスです。
Definition: CachedHeap.h:31
#define NLIB_FINAL
利用可能であればfinalが定義されます。そうでない場合は空文字列です。
Definition: Config.h:245
int errno_t
intのtypedefで、戻り値としてPOSIXのエラー値を返すことを示します。
Definition: NMalloc.h:37