]> git.lizzy.rs Git - nothing.git/blob - src/system/memory.h
Try to remove malloc from LevelEditor
[nothing.git] / src / system / memory.h
1 #ifndef MEMORY_H_
2 #define MEMORY_H_
3
4 #include <assert.h>
5 #include <stdint.h>
6
7 #define KILO 1024L
8 #define MEGA (1024L * KILO)
9 #define GIGA (1024L * MEGA)
10
11 typedef struct {
12     size_t capacity;
13     size_t size;
14     uint8_t *buffer;
15 } Memory;
16
17 static inline
18 void *memory_alloc(Memory *memory, size_t size)
19 {
20     assert(memory);
21     assert(memory->size + size <= memory->capacity);
22
23     void *result = memory->buffer + memory->size;
24     memory->size += size;
25
26     return result;
27 }
28
29 static inline
30 void memory_clean(Memory *memory)
31 {
32     assert(memory);
33     memory->size = 0;
34 }
35
36 #endif  // MEMORY_H_