summaryrefslogtreecommitdiff
path: root/common/mem.h
diff options
context:
space:
mode:
authoriamcheeseman <[email protected]>2026-04-06 17:04:05 -0400
committeriamcheeseman <[email protected]>2026-04-06 17:06:53 -0400
commit957c64c7b8b5e98d8a03dd84c7e27e7991fb9dbc (patch)
treef5fc230703791cee8d8e7851fb87eaef07ae63a2 /common/mem.h
Initial commit
Diffstat (limited to 'common/mem.h')
-rw-r--r--common/mem.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/common/mem.h b/common/mem.h
new file mode 100644
index 0000000..101f328
--- /dev/null
+++ b/common/mem.h
@@ -0,0 +1,24 @@
+#ifndef __MICRO_MEM_H__
+#define __MICRO_MEM_H__
+
+#include <stdlib.h>
+
+// NOTE: Overrides GLFW allocator
+void init_mem(void);
+void deinit_mem(void);
+void free_temp_allocs(void);
+// Temp allocation. Freed at the end of every frame. Do NOT realloc.
+void *mem_talloc(size_t size);
+
+// These mem_* functions handle the case of a bad allocation. No need to check
+// for NULL after allocating with these. In debug builds, they will also track
+// allocations and report any memory still in use when the program exits.
+
+void *mem_alloc(size_t size);
+void *mem_realloc(void *ptr, size_t new_size);
+void mem_free(void *ptr);
+
+// Returns -1 in release builds.
+int alloc_count(void);
+
+#endif // __MICRO_MEM_H__