shithub: leaf

Download patch

ref: b8628af4ceadb4749cd557e6bd3057c2639f3c97
parent: 0de3b3b18c831f45b037ae67a3742ebd2c9e9d41
author: Matthew Wang <mjw7@princeton.edu>
date: Thu Jan 23 12:00:52 EST 2020

don't format mempool region on free

--- a/LEAF/Inc/leaf-mempool.h
+++ b/LEAF/Inc/leaf-mempool.h
@@ -104,7 +104,7 @@
     
     void    tMempool_init           (tMempool* const, char* memory, size_t size);
     void    tMempool_free           (tMempool* const);
-    void    tMempool_initToPool     (tMempool* const, tMempool* const);
+    void    tMempool_initToPool     (tMempool* const, char* memory, size_t size, tMempool* const);
     void    tMempool_freeFromPool   (tMempool* const, tMempool* const);
     
     //==============================================================================
--- a/LEAF/Src/leaf-mempool.c
+++ b/LEAF/Src/leaf-mempool.c
@@ -209,8 +209,8 @@
     pool->head = freed_node;
     
     // Format the freed pool
-    char* freed_pool = (char*)freed_node->pool;
-    for (int i = 0; i < freed_node->size; i++) freed_pool[i] = 0;
+//    char* freed_pool = (char*)freed_node->pool;
+//    for (int i = 0; i < freed_node->size; i++) freed_pool[i] = 0;
 }
 
 void leaf_free(void* ptr)
@@ -299,4 +299,20 @@
     _tMempool* m = *mp;
     
     leaf_free(m);
+}
+
+void    tMempool_initToPool     (tMempool* const mp, char* memory, size_t size, tMempool* const mem)
+{
+    _tMempool* mm = *mem;
+    _tMempool* m = *mp = (_tMempool*) mpool_alloc(sizeof(_tMempool), mm->pool);
+    
+    mpool_create (memory, size, m->pool);
+}
+
+void    tMempool_freeFromPool   (tMempool* const mp, tMempool* const mem)
+{
+    _tMempool* mm = *mem;
+    _tMempool* m = *mp;
+    
+    mpool_free(m, mm->pool);
 }