Nebula
Loading...
Searching...
No Matches
win32memory.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
12#include "core/config.h"
13#include "core/debug.h"
17#include <new>
18#pragma warning (disable : 4595)
19
20namespace Memory
21{
22extern long volatile TotalAllocCount;
23extern long volatile TotalAllocSize;
24extern long volatile HeapTypeAllocCount[NumHeapTypes];
25extern long volatile HeapTypeAllocSize[NumHeapTypes];
26extern unsigned int volatile MemoryLoggingThreshold;
27extern HeapType volatile MemoryLoggingHeapType;
28
29//------------------------------------------------------------------------------
33
34extern void* Alloc(HeapType heapType, size_t size, size_t align = 16);
36extern void* Realloc(HeapType heapType, void* ptr, size_t size);
38extern void Free(HeapType heapType, void* ptr);
40extern void* AllocVirtual(size_t size);
42extern void CommitVirtual(void* ptr, size_t size);
44extern void DecommitVirtual(void* ptr, size_t size);
46extern void FreeVirtual(void* ptr, size_t size);
48extern char* DuplicateCString(const char* from);
50extern bool IsOverlapping(const unsigned char* srcPtr, size_t srcSize, const unsigned char* dstPtr, size_t dstSize);
52#define StackAlloc(size) _malloca(size);
53#define StackFree(ptr) _freea(ptr);
54
55//------------------------------------------------------------------------------
61{
62 unsigned int totalPhysical;
63 unsigned int availPhysical;
64 unsigned int totalVirtual;
65 unsigned int availVirtual;
66};
67
69extern void DumpTotalMemoryStatus();
70
71//------------------------------------------------------------------------------
77#if NEBULA_MEMORY_ADVANCED_DEBUGGING
79extern bool ValidateMemory();
81extern void Checkpoint(const char* msg);
83void EnableMemoryLogging(unsigned int threshold, HeapType heapType = InvalidHeapType);
85void DisableMemoryLogging();
87void ToggleMemoryLogging(unsigned int threshold, HeapType heapType = InvalidHeapType);
89void DumpMemoryLeaks();
90#endif
91
92#if NEBULA_MEMORY_ADVANCED_DEBUGGING
93#define __MEMORY_CHECKPOINT(s) Memory::Checkpoint(##s)
94#else
95#define __MEMORY_CHECKPOINT(s)
96#endif
97
98// FIXME: Memory-Validation disabled for now
99#define __MEMORY_VALIDATE(s)
100} // namespace Memory
101//------------------------------------------------------------------------------
102
Nebula debug macros.
Nebula compiler specific defines and configuration.
Definition arenaallocator.h:31
TotalMemoryStatus GetTotalMemoryStatus()
Get the system's total memory status.
Definition osxmemory.cc:201
__forceinline void FreeVirtual(void *ptr, size_t size)
free virtual memory
Definition posixmemory.h:146
int volatile TotalAllocSize
Definition win32memory.cc:17
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
__forceinline void CommitVirtual(void *ptr, size_t size)
commit virtual memory
Definition posixmemory.h:135
int volatile HeapTypeAllocCount[NumHeapTypes]
Definition win32memory.cc:18
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
HeapType volatile MemoryLoggingHeapType
Definition win32memory.cc:22
__forceinline void * AllocVirtual(size_t size)
allocate a range of virtual memory space
Definition posixmemory.h:112
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
void DumpTotalMemoryStatus()
Dump detail memory status information.
Definition win32memory.cc:183
__forceinline void DecommitVirtual(void *ptr, size_t size)
decommit virtual memory
Definition posixmemory.h:123
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
Central config file for memory setup on the Win32 platform.