-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add NativeFinalizer to go with malloc and calloc #910
Comments
Would it be sufficient to add a getter to the abstract class Allocator {
Pointer<T> allocate<T extends NativeType>(int byteCount, {int? alignment});
void free(Pointer<NativeType> pointer);
+ Pointer<NativeFinalizerFunction> get freeFunction;
} ? |
We would need to make it nullable, because we're not guaranteed that all functions use the same signature. (The freeFunction would then flow into a |
As suggested above, the package has now a |
Our malloc and calloc allocators use a different allocator on Windows.
This means that devs wanting to use a
NativeFinalizer
withmalloc
andcalloc
need to branch on OS.Also, devs wanting to use
NativeFinalizer
s withmalloc
andcalloc
rely on the specific memory allocator thatpackage:ffi
uses under the hood. This means we cannot change the underlying allocator without breaking dependencies.If we would provide a
NativeFinalizer
that would free the memory backed by calloc and malloc, we could change the implementation without breaking people. (Assuming they do not lookup their own "free" somewhere.)cc @timsneath heads up for package:win32
cc @mkustermann we're locked in to CoTaskMemAlloc
The text was updated successfully, but these errors were encountered: