Utility classes for Dart's FFI
Added signature for changeset 046c2003a3a6
Added tag 3.0.0-beta for changeset abb66df96ae3

heads

tip
browse log
3.0.0-beta
browse .tar.gz

clone

read-only
https://hg.sr.ht/~marvinhannott/ffi_helpers
read/write
ssh://hg@hg.sr.ht/~marvinhannott/ffi_helpers

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 over NativeType and can be easily specialized with extension methods (see for example Uint8Array). Because working with Uint8 data is so common, there already are Uint8 extensions for each 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. The 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