Array<T extends NativeType>.variableWithVariableDimension constructor
- @Since('3.7')
Annotation to specify a variable length Array with a configurable
variable dimension (dimension1
) in Structs.
Can only be used on the last field of a struct. When dimension1
is set
to a value greater than zero (0
), the last field of the struct is taken
into account in sizeOf and AllocatorAlloc.call. This is particularly
useful when working with Windows APIs, where most structs with variable
length arrays are defined to have an initial dimension of one (1
).
import 'dart:ffi';
import 'package:ffi/ffi.dart';
final class MyStruct extends Struct {
@Size()
external int length;
@Array.variableWithVariableDimension(1)
external Array<Uint8> inlineArray;
static Pointer<MyStruct> allocate(Allocator allocator, int length) {
final lengthInBytes = sizeOf<MyStruct>() + sizeOf<Uint8>() * (length - 1);
final result = allocator.allocate<MyStruct>(lengthInBytes);
result.ref.length = length;
return result;
}
}
void main() {
final myStruct = MyStruct.allocate(calloc, 10);
}
The variable length is always the outermost dimension of the array.
Do not invoke in normal code.
Implementation
@Since('3.7')
const factory Array.variableWithVariableDimension([
int dimension1,
int dimension2,
int dimension3,
int dimension4,
int dimension5,
]) = _ArraySize<T>.variableWithVariableDimension;