GameEngine/source/core_memory.c
2026-01-31 18:35:26 +01:00

44 lines
916 B
C

#include <core.h>
// Frame Allocator
__thread static char* frame_buffer = 0x00;
__thread static char* current_position = 0x00;
__thread static int buffer_size;
void* MemSet(void *dst, const char data, const size_t length) {
for (size_t i = 0; i < length; i++) {
*((char *)dst + i) = data;
}
return (dst);
}
void InitFrameAllocator(size_t n) {
frame_buffer = malloc(n);
current_position = frame_buffer;
}
void *FrameAlloc(size_t n) {
void* ret = 0x00;
if (current_position - frame_buffer + n < buffer_size) {
}
ret = current_position;
current_position += n;
return (ret);
}
void FrameReset() {
current_position = frame_buffer;
MemSet(frame_buffer, 0, buffer_size);
}
void DeleteFrameAllocator() {
current_position = NULL;
free(frame_buffer);
}
// Ressource Allocator (PreComputed);
// Fast Allocator; when the fram allocator is too short lived