diff options
Diffstat (limited to 'mem/src')
| -rw-r--r-- | mem/src/mem.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/mem/src/mem.c b/mem/src/mem.c index 9169a9f..70648c9 100644 --- a/mem/src/mem.c +++ b/mem/src/mem.c | |||
| @@ -57,14 +57,16 @@ void mem_del_(Memory* mem) { | |||
| 57 | 57 | ||
| 58 | void mem_clear_(Memory* mem) { | 58 | void mem_clear_(Memory* mem) { |
| 59 | assert(mem); | 59 | assert(mem); |
| 60 | mem->num_used_blocks = 0; | 60 | if (mem->num_blocks > 0) { |
| 61 | mem->next_free_chunk = 0; | 61 | mem->num_used_blocks = 0; |
| 62 | memset(mem->blocks, 0, mem->num_blocks * mem->block_size_bytes); | 62 | mem->next_free_chunk = 0; |
| 63 | memset(mem->chunks, 0, mem->num_blocks * sizeof(Chunk)); | 63 | memset(mem->blocks, 0, mem->num_blocks * mem->block_size_bytes); |
| 64 | 64 | memset(mem->chunks, 0, mem->num_blocks * sizeof(Chunk)); | |
| 65 | // Initialize the head as one large free chunk. | 65 | |
| 66 | Chunk* head = &mem->chunks[0]; | 66 | // Initialize the head as one large free chunk. |
| 67 | head->num_blocks = mem->num_blocks; | 67 | Chunk* head = &mem->chunks[0]; |
| 68 | head->num_blocks = mem->num_blocks; | ||
| 69 | } | ||
| 68 | } | 70 | } |
| 69 | 71 | ||
| 70 | void* mem_alloc_(Memory* mem, size_t num_blocks) { | 72 | void* mem_alloc_(Memory* mem, size_t num_blocks) { |
