History

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

Matthew Wang committed 6 years ago

Commit 44000f71 parent 28287233 files · +10 −1Browse files

Unified · Split

3 files
  1. LEAF/Inc/leaf-global.h +2 −1
  2. LEAF/Src/leaf-mempool.c +6 −0
  3. LEAF/Src/leaf.c +2 −0
LEAF/Inc/leaf-global.h+2−1
@@ -20,8 +20,9 @@ extern "C" { · 19 unmodified lines
2020 float sampleRate;
2121 float invSampleRate;
2222 int blockSize;
23− float twoPiTimesInvSampleRate;
23+ float twoPiTimesInvSampleRate;
2424 float (*random)(void);
25+ int clearOnAllocation;
2526 } LEAF;
2627
2728 extern LEAF leaf; // The global instance of LEAF.
LEAF/Src/leaf-mempool.c+6−0
@@ -141,6 +141,12 @@ void* mpool_alloc(size_t asize, mpool_t* pool) · 140 unmodified lines
141141
142142 pool->usize += header_size + node_to_alloc->size;
143143
144+ if (leaf.clearOnAllocation > 0)
145+ {
146+ char* new_pool = (char*)node_to_alloc->pool;
147+ for (int i = 0; i < node_to_alloc->size; i++) new_pool[i] = 0;
148+ }
149+
144150 // Return the pool of the allocated node;
145151 return node_to_alloc->pool;
146152 }
LEAF/Src/leaf.c+2−0
@@ -34,6 +34,8 @@ void LEAF_init(float sr, int blocksize, char* memory, size_t memorysize, float(* · 33 unmodified lines
3434 leaf.twoPiTimesInvSampleRate = leaf.invSampleRate * TWO_PI;
3535
3636 leaf.random = random;
37+
38+ leaf.clearOnAllocation = 0;
3739 }
3840
3941

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t