You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jan 17, 2024. It is now read-only.
I have a number of native libraries for sound processing that I want to expose as safe Dart wrappers. Each of these C functions takes one or more pointers to memory buffers, then performs some operation reading from or writing to these buffers. Often, a buffer used to get the output of one function can then be used as input to the next, preventing unnecessary copies.
My problem is how to represent these buffers on the Dart side. In #31, it was recommended to allocate memory on the native side, then use Pointer.asTypedList() to create the Dart counterpart. However, unless these buffers are static, I'll need to free them at some point. Ideally, this should happen automatically when the typed list on the Dart side is CG'ed. But the result of asTypedList is just a Float32List, which doesn't implement Finalizable, so I don't see a way of attaching a finalizer.
Ideally, I'd want one of the following:
asTypedList returns a value that implements Finalizable. This way, I can attach a native finalizer to it that frees the native memory.
dart:ffi offers a way to create a ByteBuffer that manages its own memory and exposes a native pointer to that memory.
Without support from dart:ffi, the best I can think of is to write a new class that implements List<double> and wraps a Float32List along with the code for automatically freeing the native memory on finalization. But that would introduce even more indirection when accessing its items from Dart, probably eliminating the performance benefits gained from not copying the buffers.
The text was updated successfully, but these errors were encountered:
I have a number of native libraries for sound processing that I want to expose as safe Dart wrappers. Each of these C functions takes one or more pointers to memory buffers, then performs some operation reading from or writing to these buffers. Often, a buffer used to get the output of one function can then be used as input to the next, preventing unnecessary copies.
My problem is how to represent these buffers on the Dart side. In #31, it was recommended to allocate memory on the native side, then use Pointer.asTypedList() to create the Dart counterpart. However, unless these buffers are static, I'll need to free them at some point. Ideally, this should happen automatically when the typed list on the Dart side is CG'ed. But the result of
asTypedList
is just aFloat32List
, which doesn't implementFinalizable
, so I don't see a way of attaching a finalizer.Ideally, I'd want one of the following:
asTypedList
returns a value that implementsFinalizable
. This way, I can attach a native finalizer to it that frees the native memory.ByteBuffer
that manages its own memory and exposes a native pointer to that memory.Without support from dart:ffi, the best I can think of is to write a new class that implements
List<double>
and wraps aFloat32List
along with the code for automatically freeing the native memory on finalization. But that would introduce even more indirection when accessing its items from Dart, probably eliminating the performance benefits gained from not copying the buffers.The text was updated successfully, but these errors were encountered: