diff options
Diffstat (limited to 'mem/src/mem.c')
-rw-r--r-- | mem/src/mem.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/mem/src/mem.c b/mem/src/mem.c index 4f5e5ef..9169a9f 100644 --- a/mem/src/mem.c +++ b/mem/src/mem.c | |||
@@ -46,17 +46,18 @@ void mem_del_(Memory* mem) { | |||
46 | if (mem->dynamic) { | 46 | if (mem->dynamic) { |
47 | if (mem->chunks) { | 47 | if (mem->chunks) { |
48 | free(mem->chunks); | 48 | free(mem->chunks); |
49 | mem->chunks = 0; | 49 | mem->chunks = nullptr; |
50 | } | 50 | } |
51 | if (mem->blocks) { | 51 | if (mem->blocks) { |
52 | free(mem->blocks); | 52 | free(mem->blocks); |
53 | mem->blocks = 0; | 53 | mem->blocks = nullptr; |
54 | } | 54 | } |
55 | } | 55 | } |
56 | } | 56 | } |
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 | mem->next_free_chunk = 0; | 61 | mem->next_free_chunk = 0; |
61 | memset(mem->blocks, 0, mem->num_blocks * mem->block_size_bytes); | 62 | memset(mem->blocks, 0, mem->num_blocks * mem->block_size_bytes); |
62 | memset(mem->chunks, 0, mem->num_blocks * sizeof(Chunk)); | 63 | memset(mem->chunks, 0, mem->num_blocks * sizeof(Chunk)); |
@@ -113,10 +114,11 @@ void* mem_alloc_(Memory* mem, size_t num_blocks) { | |||
113 | return &mem->blocks[chunk_idx * mem->block_size_bytes]; | 114 | return &mem->blocks[chunk_idx * mem->block_size_bytes]; |
114 | } else { | 115 | } else { |
115 | if (mem->trap) { | 116 | if (mem->trap) { |
116 | FAIL("Memory allocation failed, increase the allocator's capacity or " | 117 | FAIL( |
117 | "avoid fragmentation."); | 118 | "Memory allocation failed, increase the allocator's capacity or " |
119 | "avoid fragmentation."); | ||
118 | } | 120 | } |
119 | return 0; // Large-enough free chunk not found. | 121 | return nullptr; // Large-enough free chunk not found. |
120 | } | 122 | } |
121 | } | 123 | } |
122 | 124 | ||
@@ -172,7 +174,7 @@ void mem_free_(Memory* mem, void** chunk_ptr) { | |||
172 | 174 | ||
173 | mem->num_used_blocks--; | 175 | mem->num_used_blocks--; |
174 | 176 | ||
175 | *chunk_ptr = 0; | 177 | *chunk_ptr = nullptr; |
176 | } | 178 | } |
177 | 179 | ||
178 | // The handle is the chunk's index. We don't call it an index in the public API | 180 | // The handle is the chunk's index. We don't call it an index in the public API |