aboutsummaryrefslogtreecommitdiff
path: root/mem
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2023-07-16 16:31:59 -0700
committer3gg <3gg@shellblade.net>2023-07-16 16:31:59 -0700
commitecc2645ba4c44005ef13e33c79059de69b76551f (patch)
tree0a440aa55cf81d61688bbd34dfe8f07c39e55171 /mem
parentf48986597e6ff092feb0f18a79c6fa51a3f0e3bb (diff)
Add function to query pool capacity.
Diffstat (limited to 'mem')
-rw-r--r--mem/include/mem.h4
-rw-r--r--mem/src/mem.c5
2 files changed, 9 insertions, 0 deletions
diff --git a/mem/include/mem.h b/mem/include/mem.h
index 30c24fc..69f426f 100644
--- a/mem/include/mem.h
+++ b/mem/include/mem.h
@@ -79,6 +79,9 @@
79#define mem_get_chunk_handle(MEM, CHUNK_PTR) \ 79#define mem_get_chunk_handle(MEM, CHUNK_PTR) \
80 mem_get_chunk_handle_(&(MEM)->mem, CHUNK_PTR) 80 mem_get_chunk_handle_(&(MEM)->mem, CHUNK_PTR)
81 81
82/// Return the total capacity of the allocator in bytes.
83#define mem_capacity(MEM) mem_capacity_(&(MEM)->mem)
84
82/// Iterate over the used chunks of the allocator. 85/// Iterate over the used chunks of the allocator.
83/// 86///
84/// The caller can use 'i' as the index of the current chunk. 87/// The caller can use 'i' as the index of the current chunk.
@@ -147,3 +150,4 @@ void* mem_alloc_(Memory*, size_t num_blocks);
147void mem_free_(Memory*, void** chunk_ptr); 150void mem_free_(Memory*, void** chunk_ptr);
148void* mem_get_chunk_(const Memory*, size_t chunk_handle); 151void* mem_get_chunk_(const Memory*, size_t chunk_handle);
149size_t mem_get_chunk_handle_(const Memory*, const void* chunk); 152size_t mem_get_chunk_handle_(const Memory*, const void* chunk);
153size_t mem_capacity_(const Memory*);
diff --git a/mem/src/mem.c b/mem/src/mem.c
index ff97f0f..056d947 100644
--- a/mem/src/mem.c
+++ b/mem/src/mem.c
@@ -181,3 +181,8 @@ size_t mem_get_chunk_handle_(const Memory* mem, const void* chunk) {
181 assert(block_byte_index % mem->block_size_bytes == 0); 181 assert(block_byte_index % mem->block_size_bytes == 0);
182 return block_byte_index / mem->block_size_bytes; 182 return block_byte_index / mem->block_size_bytes;
183} 183}
184
185size_t mem_capacity_(const Memory* mem) {
186 assert(mem);
187 return mem->num_blocks * mem->block_size_bytes;
188}