]> git.lizzy.rs Git - nothing.git/blob - src/system/memory.h
d099d5f641505d0f84466b16c4cc2bb158845c8f
[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 1024
8 #define MEGA (1024 * KILO)
9 #define GIGA (1024 * 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
24     void *result = memory->buffer + memory->size;
25     memory->size += size;
26
27     return result;
28 }
29
30 static inline
31 void memory_clean(Memory *memory)
32 {
33     assert(memory);
34     memory->size = 0;
35 }
36
37 #endif  // MEMORY_H_