CommonLibSSE NG
Loading...
Searching...
No Matches
GMemory.h
Go to the documentation of this file.
1#pragma once
2
3#include "RE/G/GMemoryHeap.h"
4
5namespace RE
6{
7 class GMemory
8 {
9 public:
10 static void SetGlobalHeap(GMemoryHeap* a_heap);
12 static void CreateArena(UPInt a_arena, GSysAllocPaged* a_sysAlloc);
13 static void DestroyArena(UPInt a_arena);
14 static bool ArenaIsEmpty(UPInt a_arena);
15 static void* Alloc(UPInt a_count);
16 static void* Alloc(UPInt a_count, UPInt a_al);
17 static void* AllocAutoHeap(const void* a_ptr, UPInt a_count);
18 static void* AllocAutoHeap(const void* a_ptr, UPInt a_count, UPInt a_al);
19 static void* AllocInHeap(GMemoryHeap* a_heap, UPInt a_count);
20 static void* AllocInHeap(GMemoryHeap* a_heap, UPInt a_count, UPInt a_al);
21 static void* Realloc(void* a_ptr, UPInt a_newCount);
22 static void Free(void* a_ptr);
23 static void FreeInHeap(GMemoryHeap* a_heap, void* a_ptr);
24 static GMemoryHeap* GetHeapByAddress(const void* a_ptr);
25 static bool DetectMemoryLeaks();
26
27 protected:
29 };
30}
31
32// Global heap
33#define GALLOC(a_count) RE::GMemory::Alloc((a_count))
34#define GMEMALIGN(a_sz, a_al) RE::GMemory::Alloc((a_count), (a_al))
35#define GREALLOC(a_ptr, a_count) RE::GMemory::Realloc((a_ptr), (a_count))
36#define GFREE(a_ptr) RE::GMemory::Free((a_ptr))
37#define GFREE_ALIGN(a_count) RE::GMemory::Free((a_count))
38
39// Local heap
40#define GHEAP_ALLOC(a_heap, a_count) RE::GMemory::AllocInHeap((a_heap), (a_count))
41#define GHEAP_MEMALIGN(a_heap, a_count, a_al) RE::GMemory::AllocInHeap((a_heap), (a_count), (a_al))
42#define GHEAP_AUTO_ALLOC(a_addr, a_count) RE::GMemory::AllocAutoHeap((a_addr), (a_count))
43#define GHEAP_FREE(a_heap, a_ptr) RE::GMemory::FreeInHeap((a_heap), (a_ptr))
44
45#define GFC_MEMORY_REDEFINE_NEW_IMPL(a_className, a_check_delete, a_statType) \
46 void* operator new(std::size_t a_count) { return GALLOC(a_count); } \
47 void* operator new[](std::size_t a_count) { return GALLOC(a_count); } \
48 void* operator new([[maybe_unused]] std::size_t a_count, void* a_plcmnt) { return a_plcmnt; } \
49 void* operator new[]([[maybe_unused]] std::size_t a_count, void* a_plcmnt) { return a_plcmnt; } \
50 void* operator new(std::size_t a_count, RE::GMemoryHeap* a_heap) { return GHEAP_ALLOC(a_heap, a_count); } \
51 void* operator new[](std::size_t a_count, RE::GMemoryHeap* a_heap) { return GHEAP_ALLOC(a_heap, a_count); } \
52 void operator delete(void* a_ptr) { GFREE(a_ptr); } \
53 void operator delete[](void* a_ptr) { GFREE(a_ptr); } \
54 void operator delete([[maybe_unused]] void* a_ptr, [[maybe_unused]] void* a_plcmnt) {} \
55 void operator delete[]([[maybe_unused]] void* a_ptr, [[maybe_unused]] void* a_plcmnt) {} \
56 void operator delete(void* a_ptr, RE::GMemoryHeap* a_heap) { GHEAP_FREE(a_heap, a_ptr); }
57
58#define GFC_MEMORY_CHECK_DELETE_NONE(a_className, a_ptr)
59#define GFC_MEMORY_REDEFINE_NEW(a_className, a_statType) GFC_MEMORY_REDEFINE_NEW_IMPL(a_className, GFC_MEMORY_CHECK_DELETE_NONE, a_statType)
Definition GMemoryHeap.h:16
Definition GMemory.h:8
static void FreeInHeap(GMemoryHeap *a_heap, void *a_ptr)
static void * AllocAutoHeap(const void *a_ptr, UPInt a_count, UPInt a_al)
static void DestroyArena(UPInt a_arena)
static GMemoryHeap *& GetGlobalHeapRef()
static void Free(void *a_ptr)
static void * Alloc(UPInt a_count, UPInt a_al)
static bool DetectMemoryLeaks()
static void * AllocAutoHeap(const void *a_ptr, UPInt a_count)
static GMemoryHeap * GetHeapByAddress(const void *a_ptr)
static void * Alloc(UPInt a_count)
static void * AllocInHeap(GMemoryHeap *a_heap, UPInt a_count)
static void * Realloc(void *a_ptr, UPInt a_newCount)
static bool ArenaIsEmpty(UPInt a_arena)
static void * AllocInHeap(GMemoryHeap *a_heap, UPInt a_count, UPInt a_al)
static GMemoryHeap * GetGlobalHeap()
static void SetGlobalHeap(GMemoryHeap *a_heap)
static void CreateArena(UPInt a_arena, GSysAllocPaged *a_sysAlloc)
Definition GSysAllocPaged.h:11
Definition AbsorbEffect.h:6
std::size_t UPInt
Definition SFTypes.h:5