1 | initial version |
To convert a vector within a 2D array into Dart/Flutter, you can use the following steps:
int
, the struct definition in Dart/Flutter would look like this:import 'dart:ffi' as ffi;
class ExampleStruct extends ffi.Struct {
@ffi.Array.multi([10, 10]) // 10x10 2D array
late ffi.Array<ffi.Array<ffi.Int32>> vector;
}
ffi.Pointer
class to obtain a pointer to the 2D array. This pointer can be passed to an FFI function in order to operate on the array.// assuming the 2D array is named `myArray`:
var struct = ExampleStruct()
..vector = ffi.Array<ffi.Array<ffi.Int32>>.generate(
10, // outer dimension
(i) => ffi.Array<ffi.Int32>.generate(
10, // inner dimension
(j) => myArray[i][j],
),
);
var structPointer = struct.addressOf;
structPointer
to an FFI function to operate on the array.// assuming an FFI function named `operateOnArray`:
operateOnArray(structPointer);