nlib
CachedHeap.h
[詳解]
1 
2 /*---------------------------------------------------------------------------*
3 
4  Project: CrossRoad
5  Copyright (C)2012-2016 Nintendo. All rights reserved.
6 
7  These coded instructions, statements, and computer programs contain
8  proprietary information of Nintendo of America Inc. and/or Nintendo
9  Company Ltd., and are protected by Federal copyright law. They may
10  not be disclosed to third parties or copied or duplicated in any form,
11  in whole or in part, without the prior written consent of Nintendo.
12 
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;
31 
33  public:
34  CachedHeap() NLIB_NOEXCEPT : body_(NULL) {}
35  ~CachedHeap() NLIB_NOEXCEPT { this->Finalize(); }
36  NLIB_MOVE_MEMBER_HELPER_1(CachedHeap, body_);
38  using std::swap;
39  swap(body_, rhs.body_);
40  }
41 
42  void* Alloc(size_t n) NLIB_NOEXCEPT; // nmalloc()
43  void* Alloc(size_t n, size_t algn) NLIB_NOEXCEPT; // nmalloc_aligned()
44  size_t GetAllocSize(const void* p) NLIB_NOEXCEPT; // nmalloc_size()
45  errno_t Free(void* p) NLIB_NOEXCEPT; // nfree()
46  errno_t FreeWithSize(void* p, size_t size) NLIB_NOEXCEPT; // nfree_size()
47  errno_t Realloc(void* ptr, size_t size, void** p) NLIB_NOEXCEPT; // nrealloc() minus
48 
49  void ReleaseAllCache() NLIB_NOEXCEPT; // nmalloc_query(NMALLOC_QUERY_CLEAR_CACHE);
50  void Finalize() NLIB_NOEXCEPT; // nmalloc_query(NMALLOC_QUERY_FINALIZE_CACHE);
51  bool CheckCache() NLIB_NOEXCEPT;
52  errno_t QueryV(int query, va_list ap) NLIB_NOEXCEPT;
53  errno_t Query(int query, ...) NLIB_NOEXCEPT;
54 
55  // Internal use only
56  NLIB_VIS_HIDDEN void Reset(TlsHeapCache* body) NLIB_NOEXCEPT;
57  NLIB_VIS_HIDDEN TlsHeapCache* Release() NLIB_NOEXCEPT;
58 
59  NLIB_SAFE_BOOL(CachedHeap, (body_ != NULL))
60 
61  private:
62  TlsHeapCache* body_;
64 };
65 
66 } // namespace heap
67 NLIB_NAMESPACE_END
68 
69 NLIB_DEFINE_STD_SWAP(::nlib_ns::heap::CachedHeap)
70 
71 #if defined(_MSC_VER) && defined(nx_heap_EXPORTS)
72 #undef NLIB_VIS_PUBLIC
73 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT
74 #endif
75 
76 #endif // INCLUDE_NN_NLIB_HEAP_CACHEDHEAP_H_
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
TypeName で指定されたクラスのコピーコンストラクタと代入演算子を禁止します。
Definition: Config.h:158
#define NLIB_SAFE_BOOL(class_name, exp)
クラス内に安全なoperator bool()を定義します。 可能であればC++11のexplicit boolを利用します。 ...
Definition: Config.h:173
~CachedHeap() noexcept
デストラクタです。Finalize()を呼び出します。
Definition: CachedHeap.h:35
void swap(CachedHeap &rhs) noexcept
オブジェクトの内容をスワップします。
Definition: CachedHeap.h:37
#define NLIB_VIS_HIDDEN
関数やクラス等のシンボルをライブラリの外部に公開しません。
Definition: Platform_unix.h:86
#define NLIB_VIS_PUBLIC
関数やクラス等のシンボルをライブラリの外部に公開します。
Definition: Platform_unix.h:87
CachedHeap() noexcept
デフォルトコンストラクタです。
Definition: CachedHeap.h:34
#define NLIB_NOEXCEPT
環境に合わせてnoexcept 又は同等の定義がされます。
Definition: Config.h:99
開発環境別の設定が書かれるファイルです。
CentralHeapと対になって利用されるスレッド専用キャッシュクラスです。
Definition: CachedHeap.h:32
#define NLIB_FINAL
利用可能であればfinalが定義されます。そうでない場合は空文字列です。
Definition: Config.h:224
int errno_t
intのtypedefで、戻り値としてPOSIXのエラー値を返すことを示します。
Definition: NMalloc.h:37