nlib
CachedHeap.h
Go to the documentation of this file.
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;
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(kNmallocQueryClearCache);
50  void Finalize() NLIB_NOEXCEPT; // nmalloc_query(kNmallocQueryFinalizeCache);
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)
Prohibits use of the copy constructor and assignment operator for the class specified by TypeName...
Definition: Config.h:163
#define NLIB_SAFE_BOOL(class_name, exp)
Defines a safe operator bool function in the class. Uses the C++11 explicit bool if it is available f...
Definition: Config.h:178
~CachedHeap() noexcept
Destructor. Calls Finalize.
Definition: CachedHeap.h:35
void swap(CachedHeap &rhs) noexcept
Swaps the contents of an object.
Definition: CachedHeap.h:37
#define NLIB_VIS_HIDDEN
Symbols for functions and classes are not made available outside of the library.
Definition: Platform_unix.h:88
#define NLIB_VIS_PUBLIC
Symbols for functions and classes are made available outside of the library.
Definition: Platform_unix.h:89
CachedHeap() noexcept
Instantiates the object with default parameters (default constructor).
Definition: CachedHeap.h:34
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
Definition: Config.h:99
A file that contains the configuration information for each development environment.
Thread-specific cache class whose use is paired with CentralHeap.
Definition: CachedHeap.h:32
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
Definition: Config.h:229
int errno_t
Indicates with an int-type typedef that a POSIX error value is returned as the return value...
Definition: NMalloc.h:37