feat(memory): add STORM_ALLOC and STORM_NEW macros

This commit is contained in:
fallenoak 2025-09-03 23:38:18 -05:00
parent 595e431d92
commit 20457f7d4c
5 changed files with 16 additions and 8 deletions

View file

@ -99,8 +99,7 @@ void SBigMul(BigData* a, BigData* b, BigData* c) {
} }
void SBigNew(BigData** num) { void SBigNew(BigData** num) {
auto m = SMemAlloc(sizeof(BigData), __FILE__, __LINE__, 0x0); *num = STORM_NEW(BigData);
*num = new (m) BigData();
} }
void SBigNot(BigData* a, BigData* b) { void SBigNot(BigData* a, BigData* b) {

View file

@ -6,6 +6,18 @@
#define SMEM_FLAG_ZEROMEMORY 0x8 #define SMEM_FLAG_ZEROMEMORY 0x8
#define STORM_ALLOC(bytes) \
SMemAlloc(bytes, __FILE__, __LINE__, 0x0)
#define STORM_ALLOC_ZERO(bytes) \
SMemAlloc(bytes, __FILE__, __LINE__, SMEM_FLAG_ZEROMEMORY)
#define STORM_NEW(t) \
new(SMemAlloc(sizeof(t), __FILE__, __LINE__, 0x0)) t
#define STORM_NEW_ZERO(t) \
new(SMemAlloc(sizeof(t), __FILE__, __LINE__, SMEM_FLAG_ZEROMEMORY)) t
void* SMemAlloc(size_t bytes, const char* filename, int32_t linenumber, uint32_t flags = 0); void* SMemAlloc(size_t bytes, const char* filename, int32_t linenumber, uint32_t flags = 0);
void SMemCopy(void* dst, void* src, size_t bytes); void SMemCopy(void* dst, void* src, size_t bytes);

View file

@ -40,8 +40,7 @@ void* SCreateThread(uint32_t (*threadProc)(void*), void* threadParam, void* a3,
uint32_t threadId = S_Thread::s_threadID++; uint32_t threadId = S_Thread::s_threadID++;
void* m = SMemAlloc(sizeof(SThreadParmBlock), __FILE__, __LINE__, 0x8); auto params = STORM_NEW_ZERO(SThreadParmBlock);
auto params = new (m) SThreadParmBlock();
params->threadProc = threadProc; params->threadProc = threadProc;
params->threadParam = threadParam; params->threadParam = threadParam;
params->threadID = threadId; params->threadID = threadId;

View file

@ -40,8 +40,7 @@ void* SCreateThread(uint32_t (*threadProc)(void*), void* threadParam, void* a3,
uint32_t threadId = S_Thread::s_threadID++; uint32_t threadId = S_Thread::s_threadID++;
void* m = SMemAlloc(sizeof(SThreadParmBlock), __FILE__, __LINE__, 0x8); auto params = STORM_NEW_ZERO(SThreadParmBlock);
auto params = new (m) SThreadParmBlock();
params->threadProc = threadProc; params->threadProc = threadProc;
params->threadParam = threadParam; params->threadParam = threadParam;
params->threadID = threadId; params->threadID = threadId;

View file

@ -38,8 +38,7 @@ void* SCreateThread(uint32_t (*threadProc)(void*), void* threadParam, void* a3,
*/ */
} }
void* m = SMemAlloc(sizeof(SThreadParmBlock), __FILE__, __LINE__, 0x8); auto params = STORM_NEW(SThreadParmBlock);
auto params = new (m) SThreadParmBlock();
params->threadProc = threadProc; params->threadProc = threadProc;
params->threadParam = threadParam; params->threadParam = threadParam;