Nebula
Loading...
Searching...
No Matches
osxmemory.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
11#include "core/config.h"
12#include "core/debug.h"
14
15namespace Memory
16{
17extern int volatile TotalAllocCount;
18extern int volatile TotalAllocSize;
19extern int volatile HeapTypeAllocCount[NumHeapTypes];
20extern int volatile HeapTypeAllocSize[NumHeapTypes];
21extern bool volatile MemoryLoggingEnabled;
22extern unsigned int volatile MemoryLoggingThreshold;
23extern HeapType volatile MemoryLoogingHeapType;
24
25//------------------------------------------------------------------------------
29
30extern void* Alloc(HeapType heapType, size_t size, size_t alignment=16);
32extern void* Realloc(HeapType heapType, void* ptr, size_t size);
34extern void Free(HeapType heapType, void* ptr);
36extern char* DuplicateCString(const char* from);
38extern bool IsOverlapping(const unsigned char* srcPtr, size_t srcSize, const unsigned char* dstPtr, size_t dstSize);
40extern void Copy(const void* from, void* to, size_t numBytes);
42extern void Clear(void* ptr, size_t numBytes);
44extern void Fill(void* ptr, size_t numBytes, unsigned char value);
45
46//------------------------------------------------------------------------------
51struct TotalMemoryStatus
52{
53 unsigned int totalPhysical;
54 unsigned int availPhysical;
55 unsigned int totalVirtual;
56 unsigned int availVirtual;
57};
59
60//------------------------------------------------------------------------------
64#if NEBULA_MEMORY_STATS
66void EnableMemoryLogging(unsigned int threshold, HeapType = InvalidHeapType);
68void DisableMemoryLogging();
70void ToggleMemoryLogging(unsigned int threshold, HeapType = InvalidHeapType);
71#endif
72
73#if NEBULA_MEMORY_ADVANCED_DEBUGGING
75extern bool ValidateMemory();
77extern void Checkpoint(const char* msg);
79void DumpMemoryLeaks();
80#endif
81
82#if NEBULA_MEMORY_ADVANCED_DEBUGGING
83#define __MEMORY_CHECKPOINT(s) Memory::Checkpoint(##s)
84#else
85#define __MEMORY_CHECKPOINT(s)
86#endif
87
88 // FIXME: Memory-Validation disabled for now
89#define __MEMORY_VALIDATE(s)
90} // namespace Memory
91
92#ifdef new
93#undef new
94#endif
95
96#ifdef delete
97#undef delete
98#endif
99
100//------------------------------------------------------------------------------
104extern void* operator new(size_t size);
105extern void* operator new(size_t size, size_t align);
106
107extern void* operator new[](size_t size);
108extern void* operator new[](size_t size, size_t align);
109
110extern void operator delete(void* p);
111extern void operator delete[](void* p);
112
113#define n_new(type) new type
114#define n_new_array(type,size) new type[size]
115#define n_delete(ptr) delete ptr
116#define n_delete_array(ptr) delete[] ptr
117//------------------------------------------------------------------------------
118
119
Nebula debug macros.
Nebula compiler specific defines and configuration.
__forceinline unsigned int align(unsigned int alignant, unsigned int alignment)
Definition scalar.h:722
Allocates memory using the TLSF method (http://www.gii.upv.es/tlsf/files/ecrts04_tlsf....
Definition arenaallocator.h:31
TotalMemoryStatus GetTotalMemoryStatus()
Get the system's total memory status.
Definition osxmemory.cc:201
int volatile TotalAllocSize
Definition win32memory.cc:17
void Copy(const void *from, void *to, size_t numBytes)
Copy a chunk of memory (note the argument order is different from memcpy()!!!)
Definition osxmemory.cc:213
int volatile TotalAllocCount
Definition win32memory.cc:16
void * Alloc(HeapType heapType, size_t size, size_t alignment)
Allocate a block of memory from one of the global heaps.
Definition osxmemory.cc:56
int volatile HeapTypeAllocCount[NumHeapTypes]
Definition win32memory.cc:18
void Fill(void *ptr, size_t numBytes, unsigned char value)
Fill memory with a specific byte.
Definition osxmemory.cc:239
int volatile HeapTypeAllocSize[NumHeapTypes]
Definition win32memory.cc:19
void Free(HeapType heapType, void *ptr)
Free a block of memory.
Definition osxmemory.cc:136
void * Realloc(HeapType heapType, void *ptr, size_t size)
Re-Allocate a block of memory from one of the global heaps.
Definition osxmemory.cc:99
bool volatile MemoryLoggingEnabled
Definition win32memory.cc:20
char * DuplicateCString(const char *from)
Duplicate a 0-terminated string, this method should no longer be used!
Definition osxmemory.cc:166
unsigned int volatile MemoryLoggingThreshold
Definition win32memory.cc:21
HeapType
Heap types are defined here.
Definition osxmemoryconfig.h:25
@ NumHeapTypes
Definition osxmemoryconfig.h:36
@ InvalidHeapType
Definition osxmemoryconfig.h:37
bool IsOverlapping(const unsigned char *srcPtr, size_t srcSize, const unsigned char *dstPtr, size_t dstSize)
Test if 2 areas of memory areas are overlapping.
Definition osxmemory.cc:180
HeapType volatile MemoryLoogingHeapType
void Clear(void *ptr, size_t numBytes)
Overwrite a chunk of memory with 0's.
Definition osxmemory.cc:229
Math::float2 size
Definition histogramcontext.cc:36
Central config file for memory setup on the OSX platform.
Get the system's total current memory, this does not only include Nebula's memory allocations but the...
Definition win32memory.h:61
unsigned int totalVirtual
Definition osxmemory.h:55
unsigned int totalPhysical
Definition osxmemory.h:53
unsigned int availVirtual
Definition osxmemory.h:56
unsigned int availPhysical
Definition osxmemory.h:54