Files
dusklight/include/JSystem/JGadget/std-memory.h
T
PJB3005 038ef4216f Isolate JKRHeap operator overloads
Fixes #25

This isolates the JKRHeap operator new/delete overloads. Every single new/delete site in the code has been replaced with a macro.

Sadly for new[] and delete[] we have to keep global operators. The global new[] just allocates into malloc() however, and delete[] goes into free() if it's not in a JKRHeap. So that's fine.
2026-02-27 23:11:59 +01:00

41 lines
767 B
C++

#ifndef STD_MEMORY_H
#define STD_MEMORY_H
#include "JSystem/JUtility/JUTAssert.h"
#include "JSystem/JKernel/JKRHeap.h"
namespace JGadget {
template <typename T>
struct TAllocator {
T* allocate(u32 count, const void *param_2) {
return AllocateRaw(count * sizeof(T));
}
T* AllocateRaw(u32 size) {
return (T*)operator new(size);
}
void deallocate(T* mem, u32 size) {
DeallocateRaw(mem);
}
void DeallocateRaw(void* mem) {
JKR_DELETE(mem);
}
void construct(T* p, const T& other) {
JUT_ASSERT(67, p!=NULL);
JKR_NEW_ARGS(p) T(other);
}
void destroy(T* p) {
(void)p;
JUT_ASSERT(68, p!=NULL);
}
/* 0x0 */ u8 mAllocator;
};
}
#endif /* STD_MEMORY_H */