aboutsummaryrefslogtreecommitdiff
path: root/mem/src
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2025-08-19 18:22:34 +0200
committer3gg <3gg@shellblade.net>2025-08-19 18:22:34 +0200
commite5eb3845eff1ea080ffdc08102f7d1a6dee1179f (patch)
tree44de98ab673d1cd5239e97616f3c9eae54a471f8 /mem/src
parent8bea2bac950f6716fbf26bcd2c718e048f77c9b7 (diff)
Add tests for clearing uninitialized memory allocatorsHEADmain
Diffstat (limited to 'mem/src')
-rw-r--r--mem/src/mem.c18
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
58void mem_clear_(Memory* mem) { 58void 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
70void* mem_alloc_(Memory* mem, size_t num_blocks) { 72void* mem_alloc_(Memory* mem, size_t num_blocks) {