nlib
CentralHeap.h
Go to the documentation of this file.
1 
2 #pragma once
3 #ifndef INCLUDE_NN_NLIB_HEAP_CENTRALHEAP_H_
4 #define INCLUDE_NN_NLIB_HEAP_CENTRALHEAP_H_
5 
6 #include "nn/nlib/heap/NMalloc.h"
7 
8 #if defined(_MSC_VER) && defined(nx_heap_EXPORTS)
9 #undef NLIB_VIS_PUBLIC
10 #define NLIB_VIS_PUBLIC NLIB_WINEXPORT
11 #endif
12 
13 NLIB_NAMESPACE_BEGIN
14 namespace heap {
15 
16 class CachedHeap;
17 class TlsHeapCentral;
19  public:
20  typedef void (*DestructorHandler)(void* start, void* end);
21 
22  CentralHeap() NLIB_NOEXCEPT : m_Central(NULL),
23  m_UseVirtualMemory(false),
24  m_HeapOption(0),
25  m_Start(NULL),
26  m_End(NULL) {}
27  ~CentralHeap() NLIB_NOEXCEPT { this->Finalize(); }
28  errno_t Initialize(void* start, size_t size, uint32_t heap_option) NLIB_NOEXCEPT;
29  void Finalize() NLIB_NOEXCEPT;
30  NLIB_ALWAYS_INLINE void* Alloc(size_t n) NLIB_NOEXCEPT { return this->Alloc(n, 8); }
31  void* Alloc(size_t n, size_t algn) NLIB_NOEXCEPT;
32  errno_t Free(void* p) NLIB_NOEXCEPT;
33 
34  bool IsClean() NLIB_NOEXCEPT;
35  bool MakeCache(CachedHeap* ptr) NLIB_NOEXCEPT;
36  void CalcHeapHash(HeapHash* hash) NLIB_NOEXCEPT;
37  void DumpEx(NMallocDumpMode mode, nlib_fd fd) const NLIB_NOEXCEPT;
38  void DumpEx(NMallocDumpMode mode) const NLIB_NOEXCEPT { DumpEx(mode, 1); }
39  void Dump() const NLIB_NOEXCEPT { DumpEx(NMALLOC_DUMP_BASIC, 1); }
40  errno_t WalkAllocatedPtrs(nmalloc_heapwalk_callback func, void* user_ptr) NLIB_NOEXCEPT;
41  static const size_t kPageSize;
42 
43  private:
44  TlsHeapCentral* m_Central;
45  bool m_UseVirtualMemory;
46  uint32_t m_HeapOption;
47  uint8_t* m_Start;
48  uint8_t* m_End;
50 };
51 
52 } // namespace heap
53 NLIB_NAMESPACE_END
54 
55 #if defined(_MSC_VER) && defined(nx_heap_EXPORTS)
56 #undef NLIB_VIS_PUBLIC
57 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT
58 #endif
59 
60 #endif // INCLUDE_NN_NLIB_HEAP_CENTRALHEAP_H_
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
Definition: Platform.h:2151
int(* nmalloc_heapwalk_callback)(void *allocated_ptr, size_t size, void *user_ptr)
User-defined callback function that is called from nmalloc_walk_allocated_ptrs.
Definition: NMalloc.h:67
void Dump() const noexcept
Runs DumpEx(NMALLOC_DUMP_BASIC, 1).
Definition: CentralHeap.h:39
CentralHeap() noexcept
Instantiates the object with default parameters (default constructor).
Definition: CentralHeap.h:22
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
#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:126
File that defines functions including nmalloc and nfree.
~CentralHeap() noexcept
Destructor.
Definition: CentralHeap.h:27
static const size_t kPageSize
Page size of the heap (not related to the operating system page size).
Definition: CentralHeap.h:41
Central heap class whose use is paired with CachedHeap. It is used to implement nmalloc.
Definition: CentralHeap.h:18
void DumpEx(NMallocDumpMode mode) const noexcept
For more information, see nmalloc_dumpex.
Definition: CentralHeap.h:38
void * Alloc(size_t n) noexcept
Allocates a memory block.
Definition: CentralHeap.h:30
int nlib_fd
The original file descriptor of nlib (a 32-bit integer value).
Definition: Platform.h:1051
Only displays basic information.
Definition: NMalloc.h:61
Thread-specific cache class whose use is paired with CentralHeap.
Definition: CachedHeap.h:19
#define NLIB_ALWAYS_INLINE
Indicates that the compiler is forced to perform inline expansion of functions.
Definition: Platform_unix.h:59
#define NLIB_VIS_PUBLIC
Symbols for functions and classes are made available outside of the library.
Definition: Platform_unix.h:51
NMallocDumpMode
Type of the argument to pass to nmalloc_dumpex.
Definition: NMalloc.h:60
Structure that contains a summary of the memory usage status of the heap used by the user application...
Definition: NMalloc.h:31
int errno_t
Indicates with an int-type typedef that a POSIX error value is returned as the return value...
Definition: NMalloc.h:24