summaryrefslogtreecommitdiff
path: root/mem-pool.h
diff options
context:
space:
mode:
authorLibravatar Jameson Miller <jamill@microsoft.com>2018-07-02 19:49:34 +0000
committerLibravatar Junio C Hamano <gitster@pobox.com>2018-07-03 10:58:27 -0700
commit158dfeff3dc1d155b84e68b265a9b6c265717e1e (patch)
treebc4f3dee7fa51f28ea50645d59668a59799c2899 /mem-pool.h
parentmem-pool: only search head block for available space (diff)
downloadtgif-158dfeff3dc1d155b84e68b265a9b6c265717e1e.tar.xz
mem-pool: add life cycle management functions
Add initialization and discard functions to mem_pool type. As the memory allocated by mem_pool can now be freed, we also track the large allocations. If the there are existing mp_blocks in the mem_poo's linked list of mp_blocksl, then the mp_block for a large allocation is inserted behind the head block. This is because only the head mp_block is considered when searching for availble space. This results in the following desirable properties: 1) The mp_block allocated for the large request will not be included not included in the search for available in future requests, the large mp_block is sized for the specific request and does not contain any spare space. 2) The head mp_block will not bumped from considation for future memory requests just because a request for a large chunk of memory came in. These changes are in preparation for a future commit that will utilize creating and discarding memory pool. Signed-off-by: Jameson Miller <jamill@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'mem-pool.h')
-rw-r--r--mem-pool.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/mem-pool.h b/mem-pool.h
index 829ad58ecf..f75b3365d5 100644
--- a/mem-pool.h
+++ b/mem-pool.h
@@ -22,6 +22,16 @@ struct mem_pool {
};
/*
+ * Initialize mem_pool with specified initial size.
+ */
+void mem_pool_init(struct mem_pool **mem_pool, size_t initial_size);
+
+/*
+ * Discard a memory pool and free all the memory it is responsible for.
+ */
+void mem_pool_discard(struct mem_pool *mem_pool);
+
+/*
* Alloc memory from the mem_pool.
*/
void *mem_pool_alloc(struct mem_pool *pool, size_t len);