Utility classes to make working with Dart's FFI a little bit simpler and more efficient.
This package contains some utility classes to make working with Dart's FFI a little bit simpler and more efficient. You should be familiar with Dart's FFI. You find practical code examples in the api-documentation.
All classes are generic and take a
NativeType and its associated
List<int> type like
Uint8List. You can specialize each class by extending it like
class Uint8Array extends Array<Uint8,Uint8List>. Because working with Uint8 data is so common, there already is a specialized Uint8 variant of each utility class.
Don't forget to free memory with
delete() or else you will leak memory. Use after free leads to undefined behavior, so watch out.
Working with pointers can be tricky because they don't know their size, and getting the size wrong can lead to undefined behavior and hard to locate bugs.
Array class can alleviate that situation, making working with arrays simpler and safer.
Often multiple parts of your code could share a single memory buffer, but that always rises the question of ownership: who has to clean up and when? The reference counted
SharedArray solves this problem.
When you have to make many little memory allocations, consider using
Arena to do arena / region-based allocation.
Arena lets you allocate a large chunk of memory which can then be sliced into smaller views. The allocated memory can then be released in one operation. This kind of memory management can lead to drastic performance improvements and fewer bugs.
Issues can be reported to the ffi_helpers issue tracker