nlib
CachedHeap.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_CACHEDHEAP_H_
17 #define INCLUDE_NN_NLIB_HEAP_CACHEDHEAP_H_
18 
19 #include "nn/nlib/Config.h"
20 #include "nn/nlib/Swap.h"
21 
22 #if defined(_MSC_VER) && defined(nx_heap_EXPORTS)
23 #undef NLIB_VIS_PUBLIC
24 #define NLIB_VIS_PUBLIC NLIB_WINEXPORT
25 #endif
26 
27 NLIB_NAMESPACE_BEGIN
28 namespace heap {
29 
30 class TlsHeapCache;
32  public:
33  NLIB_CEXPR CachedHeap() NLIB_NOEXCEPT : prv_(nullptr) {}
34  ~CachedHeap() NLIB_NOEXCEPT { this->Finalize(); }
35  NLIB_DEFMOVE_PIMPL(CachedHeap);
36 
37  void* Alloc(size_t n) NLIB_NOEXCEPT; // nmalloc()
38  void* Alloc(size_t n, size_t algn) NLIB_NOEXCEPT; // nmalloc_aligned()
39  size_t GetAllocSize(const void* p) NLIB_NOEXCEPT; // nmalloc_size()
40  errno_t Free(void* p) NLIB_NOEXCEPT; // nfree()
41  errno_t FreeWithSize(void* p, size_t size) NLIB_NOEXCEPT; // nfree_size()
42  errno_t Realloc(void* ptr, size_t size, void** p) NLIB_NOEXCEPT; // nrealloc() minus
43 
44  void ReleaseAllCache() NLIB_NOEXCEPT; // nmalloc_query(kNmallocQueryClearCache);
45  void Finalize() NLIB_NOEXCEPT; // nmalloc_query(kNmallocQueryFinalizeCache);
46  bool CheckCache() NLIB_NOEXCEPT;
47  errno_t QueryV(int query, va_list ap) NLIB_NOEXCEPT;
48  errno_t Query(int query, ...) NLIB_NOEXCEPT;
49  void Reset() NLIB_NOEXCEPT { this->Finalize(); }
50 
51  // Internal use only
52  NLIB_VIS_HIDDEN void Reset(TlsHeapCache* body) NLIB_NOEXCEPT;
53  NLIB_VIS_HIDDEN TlsHeapCache* Release() NLIB_NOEXCEPT;
54 
55  NLIB_SAFE_BOOL(CachedHeap, (prv_ != nullptr))
56 
57  private:
58  TlsHeapCache* prv_;
60 };
61 
62 } // namespace heap
63 NLIB_NAMESPACE_END
64 
65 NLIB_DEFINE_STD_SWAP(::nlib_ns::heap::CachedHeap)
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_CACHEDHEAP_H_
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
TypeName で指定されたクラスのコピーコンストラクタと代入演算子を禁止します。
Definition: Config.h:183
#define NLIB_SAFE_BOOL(class_name, exp)
クラス内に安全なoperator bool()を定義します。 可能であればC++11のexplicit boolを利用します。 ...
Definition: Config.h:199
~CachedHeap() noexcept
デストラクタです。 Finalize()を呼び出します。
Definition: CachedHeap.h:34
#define NLIB_VIS_HIDDEN
関数やクラス等のシンボルをライブラリの外部に公開しません。
Definition: Platform_unix.h:86
#define NLIB_VIS_PUBLIC
関数やクラス等のシンボルをライブラリの外部に公開します。
Definition: Platform_unix.h:87
constexpr CachedHeap() noexcept
デフォルトコンストラクタです。
Definition: CachedHeap.h:33
共通して使われることの多いストリーム関連のクラス群や各種コンテナ、及びガシェットクラスが実装されてい...
Definition: Base64.h:25
#define NLIB_NOEXCEPT
環境に合わせてnoexcept 又は同等の定義がされます。
Definition: Config.h:109
#define NLIB_CEXPR
利用可能であればconstexprが定義されます。そうでない場合は空文字列です。
Definition: Config.h:111
開発環境別の設定が書かれるファイルです。
CentralHeapと対になって利用されるスレッド専用キャッシュクラスです。
Definition: CachedHeap.h:31
#define NLIB_FINAL
利用可能であればfinalが定義されます。そうでない場合は空文字列です。
Definition: Config.h:250
int errno_t
intのtypedefで、戻り値としてPOSIXのエラー値を返すことを示します。
Definition: NMalloc.h:37