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.
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 isDrop
ed. 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 anstd:Rc
andstd::RefCell
to handle the borrow/drop trickery.