aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mem/include/mem.h4
-rw-r--r--mem/src/mem.c5
-rw-r--r--mempool/include/mempool.h4
-rw-r--r--mempool/src/mempool.c5
4 files changed, 18 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}
diff --git a/mempool/include/mempool.h b/mempool/include/mempool.h
index b76ae7c..8251a70 100644
--- a/mempool/include/mempool.h
+++ b/mempool/include/mempool.h
@@ -80,6 +80,9 @@
80#define mempool_get_block_index(POOL, BLOCK_PTR) \ 80#define mempool_get_block_index(POOL, BLOCK_PTR) \
81 mempool_get_block_index_(&(POOL)->pool, BLOCK_PTR) 81 mempool_get_block_index_(&(POOL)->pool, BLOCK_PTR)
82 82
83/// Return the total capacity of the mempool in bytes.
84#define mempool_capacity(POOL) mempool_capacity_(&(POOL)->pool)
85
83/// Iterate over the used blocks of the pool. 86/// Iterate over the used blocks of the pool.
84/// 87///
85/// The caller can use 'i' as the index of the current block. 88/// The caller can use 'i' as the index of the current block.
@@ -133,3 +136,4 @@ void* mempool_alloc_(mempool*);
133void mempool_free_(mempool*, void** block_ptr); 136void mempool_free_(mempool*, void** block_ptr);
134void* mempool_get_block_(const mempool*, size_t block_index); 137void* mempool_get_block_(const mempool*, size_t block_index);
135size_t mempool_get_block_index_(const mempool*, const void* block); 138size_t mempool_get_block_index_(const mempool*, const void* block);
139size_t mempool_capacity_(const mempool*);
diff --git a/mempool/src/mempool.c b/mempool/src/mempool.c
index fdb5f8c..679f124 100644
--- a/mempool/src/mempool.c
+++ b/mempool/src/mempool.c
@@ -124,3 +124,8 @@ size_t mempool_get_block_index_(const mempool* pool, const void* block) {
124 assert(block_byte_index % pool->block_size_bytes == 0); 124 assert(block_byte_index % pool->block_size_bytes == 0);
125 return block_byte_index / pool->block_size_bytes; 125 return block_byte_index / pool->block_size_bytes;
126} 126}
127
128size_t mempool_capacity_(const mempool* pool) {
129 assert(pool);
130 return pool->num_blocks * pool->block_size_bytes;
131}