ffi_helper 2.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 85

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. 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

1.0.0+ #

  • dropped, shouldn't be used

2.0.0 - 2.0.0+2 #

  • add thin Array wrapper to manage view into contiguous memory
  • add Arena class for arena allocation
  • add SharedArray for shared (reference counted) memory

2.0.1 #

  • fix subclassing problem of Array

2.1.0 #

  • Array gets a delete() method (just sugar for free(array.ptr))

example/ffi_helper_example.dart

import 'package:ffi_helper/ffi_helper.dart';

void main() {
  Uint8Array(3);
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  ffi_helper: ^2.1.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:ffi_helper/ffi_helper.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
69
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
85
Learn more about scoring.

We analyzed this package on Jul 11, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14

Analysis suggestions

Package not compatible with runtime flutter-web on web

Because:

  • package:ffi_helper/ffi_helper.dart that imports:
  • package:ffi_helper/src/shared_array.dart that imports:
  • package:ffi/ffi.dart that imports:
  • package:ffi/src/allocation.dart that imports:
  • dart:io

Package not compatible with runtime js

Because:

  • package:ffi_helper/ffi_helper.dart that imports:
  • package:ffi_helper/src/shared_array.dart that imports:
  • package:ffi/ffi.dart that imports:
  • package:ffi/src/allocation.dart that imports:
  • dart:io

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.8.1 <3.0.0
ffi ^0.1.3 0.1.3
Dev dependencies
pedantic ^1.9.0
test ^1.14.4