alesgenova / pitch-detection

A collection of algorithms to determine the pitch of a sound sample.
MIT License
231 stars 27 forks source link

Dynamic buffer allocation #16

Closed siefkenj closed 3 years ago

siefkenj commented 3 years ago

This PR builds off of #15 It adds a BufferPool object which will allocate as many buffers as needed. Once a buffer is allocated, it is never freed, but it is reused when it is Droped. This should mean no memory leaks in WASM code and function callers don't need to care about the number of buffers a particular algorithm requires.

Benchmarks show there is no performance impact.

Let me know what you think of this approach :-). I don't love the &mut buf_ref.borrow_mut()[..] syntax, but I wasn't sure how to avoid it, since I used an std:Rc and std::RefCell to handle the borrow/drop trickery.

siefkenj commented 3 years ago

@alesgenova Any chance of a review?