From d22337cb86b196ce6a953219fa4bd46a31d144dd Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Sat, 7 Jan 2023 11:48:35 -0800 Subject: Format. --- mempool/src/mempool.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'mempool') diff --git a/mempool/src/mempool.c b/mempool/src/mempool.c index b7e8705..5772883 100644 --- a/mempool/src/mempool.c +++ b/mempool/src/mempool.c @@ -4,18 +4,19 @@ static inline size_t min(size_t a, size_t b) { return a < b ? a : b; } -void mempool_make_(mempool* pool, BlockInfo* block_info, void* blocks, - size_t num_blocks, size_t block_size_bytes) { +void mempool_make_( + mempool* pool, BlockInfo* block_info, void* blocks, size_t num_blocks, + size_t block_size_bytes) { assert(pool); assert(block_info); assert(blocks); assert(num_blocks >= 1); pool->block_size_bytes = block_size_bytes; - pool->num_blocks = num_blocks; - pool->next_free_block = 0; - pool->full = false; - pool->block_info = block_info; - pool->blocks = blocks; + pool->num_blocks = num_blocks; + pool->next_free_block = 0; + pool->full = false; + pool->block_info = block_info; + pool->blocks = blocks; memset(blocks, 0, num_blocks * block_size_bytes); } @@ -47,6 +48,8 @@ void mempool_free_(mempool* pool, void** block_ptr) { assert(pool); assert(block_ptr); + // Zero out the block so that we don't get stray values the next time it is + // allocated. memset(*block_ptr, 0, pool->block_size_bytes); const size_t block_index = @@ -59,7 +62,7 @@ void mempool_free_(mempool* pool, void** block_ptr) { pool->block_info[block_index].used = false; if (pool->full) { pool->next_free_block = block_index; - pool->full = false; + pool->full = false; } else { // Prefer to allocate blocks towards the start of the pool. This way, blocks // should cluster around this area and the pool should offer better memory -- cgit v1.2.3