shithub: leaf

Download patch

ref: 44000f7c080d0ab0702ffb79a3858df84b583370
parent: 28287230d625b580a9bd81ef9805011ec0c8ac97
author: Matthew Wang <mjw7@princeton.edu>
date: Thu Feb 27 10:52:43 EST 2020

trying out leaf setting to determine whether to clear memory on allocation

--- a/LEAF/Inc/leaf-global.h
+++ b/LEAF/Inc/leaf-global.h
@@ -20,8 +20,9 @@
         float   sampleRate;
         float   invSampleRate;
         int     blockSize;
-        float    twoPiTimesInvSampleRate;
+        float   twoPiTimesInvSampleRate;
         float   (*random)(void);
+        int     clearOnAllocation;
     } LEAF;
     
     extern LEAF leaf; // The global instance of LEAF.
--- a/LEAF/Src/leaf-mempool.c
+++ b/LEAF/Src/leaf-mempool.c
@@ -141,6 +141,12 @@
     
     pool->usize += header_size + node_to_alloc->size;
     
+    if (leaf.clearOnAllocation > 0)
+    {
+        char* new_pool = (char*)node_to_alloc->pool;
+        for (int i = 0; i < node_to_alloc->size; i++) new_pool[i] = 0;
+    }
+    
     // Return the pool of the allocated node;
     return node_to_alloc->pool;
 }
--- a/LEAF/Src/leaf.c
+++ b/LEAF/Src/leaf.c
@@ -34,6 +34,8 @@
     leaf.twoPiTimesInvSampleRate = leaf.invSampleRate * TWO_PI;
 
     leaf.random = random;
+    
+    leaf.clearOnAllocation = 0;
 }