|
|
@@ -1,5 +1,6 @@ |
|
|
|
#define STB_SPRINTF_IMPLEMENTATION |
|
|
|
#include "core.h" |
|
|
|
#include "os.h" |
|
|
|
|
|
|
|
void *pushSize(Arena *arena, size_t bytes) { |
|
|
|
if (arena->capacity - arena->head >= bytes) { |
|
|
@@ -11,11 +12,7 @@ void *pushSize(Arena *arena, size_t bytes) { |
|
|
|
} |
|
|
|
|
|
|
|
Arena *arenaAlloc(size_t capacity) { |
|
|
|
#if OS_WINDOWS |
|
|
|
Arena *result = (Arena *)VirtualAlloc(NULL, sizeof(Arena) + capacity, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); |
|
|
|
#elif OS_LINUX |
|
|
|
Arena *result = (Arena *)mmap(0, capacity, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); |
|
|
|
#endif |
|
|
|
Arena *result = (Arena *)os_alloc(sizeof(Arena) + capacity); |
|
|
|
result->memory = result + sizeof(Arena); |
|
|
|
result->capacity = capacity; |
|
|
|
result->head = 0; |
|
|
@@ -23,6 +20,7 @@ Arena *arenaAlloc(size_t capacity) { |
|
|
|
} |
|
|
|
|
|
|
|
void arenaFree(Arena *arena) { |
|
|
|
os_free(arena); |
|
|
|
#if OS_WINDOWS |
|
|
|
VirtualFree(arena, NULL, MEM_RELEASE); |
|
|
|
#elif OS_LINUX |
|
|
@@ -315,9 +313,9 @@ string readEntireFile(Arena *arena, string filename) { |
|
|
|
} |
|
|
|
return result; |
|
|
|
#elif OS_LINUX |
|
|
|
FILE *input = fopen((char *)file.str, "r"); |
|
|
|
FILE *input = fopen((char *)filename.str, "r"); |
|
|
|
struct stat st; |
|
|
|
stat((char *)file.str, &st); |
|
|
|
stat((char *)filename.str, &st); |
|
|
|
size_t fsize = st.st_size; |
|
|
|
string readBuffer = PushString(arena, filesize); |
|
|
|
readBuffer.length = filesize; |
|
|
|