How does the Dart VM manage OS threads under the hood when multiple isolates are created?

You need to use FFI but you should not need to write any native code for that:

import 'package:ffi/ffi.dart';

final mem = malloc.allocate<Uint8>(n);
final list = mem.asTypedList(n, finalizer: malloc.nativeFree);

// You can sent `mem` to another isolate and there `asTypeList` it.

This is all you need. Just need to be careful with finalization (don’t attach multiple finalizers or you would need more complicated lifetime management scheme with ref counting).

11 Likes