Nebula
Loading...
Searching...
No Matches
osxheap.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
12#include "core/types.h"
13
14//------------------------------------------------------------------------------
15namespace OSX
16{
18{
19public:
21 static void Setup();
23 OSXHeap(const char* name, size_t initialSize=64 * 1024);
25 ~OSXHeap();
27 const char* GetName() const;
29 void* Alloc(size_t size, size_t alignment=16);
31 void* Realloc(void* ptr, size_t newSize);
33 void Free(void* ptr);
34
35 #if NEBULA_MEMORY_STATS
37 struct Stats
38 {
39 const char* name;
40 int allocCount;
41 int allocSize;
42 };
44 static Util::Array<Stats> GetAllHeapStats();
46 static bool ValidateAllHeaps();
48 bool ValidateHeap() const;
50 void DumpLeaks();
52 static void DumpLeaksAllHeaps();
54 int GetAllocCount() const;
56 int GetAllocSize() const;
57#endif
58
59private:
62
63 const char* name;
64 malloc_zone_t* heapZone;
65
66 #if NEBULA_MEMORY_STATS
67 int volatile allocCount;
68 int volatile allocSize;
69 static Threading::CriticalSection* criticalSection;
70 static Util::List<OSXHeap*>* list;
72 #endif
73};
74
75//------------------------------------------------------------------------------
78inline const char*
80{
81 n_assert(0 != this->name);
82 return this->name;
83}
84
85} // namespace OSX
OSX implementation of Memory::Heap.
Definition osxheap.h:18
OSXHeap()
default constructor not allowed
void Free(void *ptr)
free a block of memory
Definition osxheap.cc:121
~OSXHeap()
destructor
Definition osxheap.cc:56
void * Realloc(void *ptr, size_t newSize)
re-allocate a block of memory
Definition osxheap.cc:100
malloc_zone_t * heapZone
Definition osxheap.h:64
static void Setup()
static setup method (called by Core::SysFunc::Setup)
Definition osxheap.cc:24
const char * name
Definition osxheap.h:63
void * Alloc(size_t size, size_t alignment=16)
allocate a block of memory from the heap
Definition osxheap.cc:81
const char * GetName() const
get heap name
Definition osxheap.h:79
Critical section objects are used to protect a portion of code from parallel execution.
Nebula's dynamic array class.
Definition array.h:60
the list iterator
Definition list.h:76
Implements a doubly linked list.
Definition list.h:20
#define n_assert(exp)
Definition debug.h:50
Definition osxsysfunc.h:21