chore(memory): rely on external dependency for allocation functions

This commit is contained in:
phaneron 2023-08-04 20:44:16 -04:00
parent cf8b5dead1
commit ef7507727b
4 changed files with 5 additions and 76 deletions

View file

@ -1,66 +0,0 @@
#include "storm/Memory.hpp"
constexpr size_t ALIGNMENT = 8;
void* SMemAlloc(size_t bytes, const char* filename, int32_t linenumber, uint32_t flags) {
size_t alignedBytes = (bytes + (ALIGNMENT - 1)) & ~(ALIGNMENT - 1);
void* result;
if (flags & 0x8) {
result = calloc(1, alignedBytes);
} else {
result = malloc(alignedBytes);
}
if (result) {
return result;
} else {
// TODO handle errors
return nullptr;
}
}
void SMemFree(void* ptr) {
if (ptr) {
free(ptr);
}
}
void SMemFree(void* ptr, const char* filename, int32_t linenumber, uint32_t flags) {
if (ptr) {
free(ptr);
}
}
void* SMemReAlloc(void* ptr, size_t bytes, const char* filename, int32_t linenumber, uint32_t flags) {
if (flags == 0xB00BEEE5) {
return nullptr;
}
if (!ptr) {
return SMemAlloc(bytes, filename, linenumber, flags);
}
if (flags & 0x10) {
return nullptr;
}
size_t alignedBytes = (bytes + (ALIGNMENT - 1)) & ~(ALIGNMENT - 1);
void* result = realloc(ptr, alignedBytes);
if (result) {
if (flags & 0x8) {
// TODO zero out expanded portion
}
return result;
} else {
if (alignedBytes) {
// TODO handle errors
}
return nullptr;
}
}

View file

@ -1,15 +1,6 @@
#ifndef STORM_MEMORY_HPP
#define STORM_MEMORY_HPP
#include <cstdint>
#include <cstdlib>
void* SMemAlloc(size_t bytes, const char* filename, int32_t linenumber, uint32_t flags);
void SMemFree(void* ptr);
void SMemFree(void* ptr, const char* filename, int32_t linenumber, uint32_t flags);
void* SMemReAlloc(void* ptr, size_t bytes, const char* filename, int32_t linenumber, uint32_t flags);
#include <mem/Memory.hpp>
#endif