mirror of
https://github.com/thunderbrewhq/squall.git
synced 2026-02-04 00:49:08 +00:00
feat(memory): replace global new and delete operators
This commit is contained in:
parent
20457f7d4c
commit
f75d9caba3
2 changed files with 38 additions and 0 deletions
|
|
@ -4,6 +4,26 @@
|
|||
|
||||
constexpr size_t ALIGNMENT = 8;
|
||||
|
||||
void* operator new(size_t bytes) {
|
||||
return SMemAlloc(bytes, "new", -1, 0x0);
|
||||
}
|
||||
|
||||
void* operator new[](size_t bytes) {
|
||||
return SMemAlloc(bytes, "new[]", -1, 0x0);
|
||||
}
|
||||
|
||||
void operator delete(void* ptr) noexcept {
|
||||
if (ptr) {
|
||||
SMemFree(ptr, "delete", -1, 0x0);
|
||||
}
|
||||
}
|
||||
|
||||
void operator delete[](void* ptr) noexcept {
|
||||
if (ptr) {
|
||||
SMemFree(ptr, "delete[]", -1, 0x0);
|
||||
}
|
||||
}
|
||||
|
||||
void* SMemAlloc(size_t bytes, const char* filename, int32_t linenumber, uint32_t flags) {
|
||||
size_t alignedBytes = (bytes + (ALIGNMENT - 1)) & ~(ALIGNMENT - 1);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue