-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[vm/ffi] Inline multi-dimensional arrays #45023
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Or using the initializer: class MyStruct {
Array<Int8> a = Array(8);
Array<Array<Int8>> b = Array(2, 4);
Array<Array<Array<Array<Int8>>>> c = Array.multi([2,3,4,5]);
}
external const Array(int firstDimension, [int dimension2, int dimension3, int dimension4, int dimension5]);
external const Array.multi(List<int> dimensions); Credits to @lrhn |
After some more discussion: keeping the annotations for consistency and enforcing const size arguments. We use class MyStruct extends Struct {
@Array(8)
external Array<Uint8> inlineArray;
@Array(2, 2, 2)
external Array<Array<Array<Uint8>>> threeDimensionalInlineArray;
@Array.multi([2, 2, 2, 2, 2, 2, 2, 2])
external Array<Array<Array<Array<Array<Array<Array<Array<Uint8>>>>>>>> eightDimensionalInlineArray;
} /// A fixed-sized array of [T]s.
class Array<T extends NativeType> extends NativeType {
/// Const constructor to specify [Array] dimensions in [Struct]s.
///
/// ```
/// class MyStruct extends Struct {
/// @Array(8)
/// external Array<Uint8> inlineArray;
///
/// @Array(2, 2, 2)
/// external Array<Array<Array<Uint8>>> threeDimensionalInlineArray;
/// }
/// ```
///
/// Do not invoke in normal code.
external const factory Array(int dimension1,
[int dimension2, int dimension3, int dimension4, int dimension5]);
/// Const constructor to specify [Array] dimensions in [Struct]s.
///
/// ```
/// class MyStruct extends Struct {
/// @Array.multi([2, 2, 2])
/// external Array<Array<Array<Uint8>>> threeDimensionalInlineArray;
///
/// @Array.multi([2, 2, 2, 2, 2, 2, 2, 2])
/// external Array<Array<Array<Array<Array<Array<Array<Array<Uint8>>>>>>>> eightDimensionalInlineArray;
/// }
/// ```
///
/// Do not invoke in normal code.
external const factory Array.multi(List<int> dimensions);
} |
Shouldn't
be /// @Array.multi([2, 2, 2])
/// external Array<Array<Array<Uint8>>> threeDimensionalInlineArray; and similarly for the other examples (good luck with fitting the eight-dimensional case on one line). |
Good catch, updated! |
What if the size of the multi-dimensional arrays will be only available during runtime (during c++ function execution)? |
@ishomam that would be a |
Uh oh!
There was an error while loading. Please reload this page.
Follow up of #35763
Context: https://dart-review.googlesource.com/c/sdk/+/183640/21/pkg/front_end/testcases/general_nnbd_opt_out/ffi_struct_inline_array.dart#12
Or
The text was updated successfully, but these errors were encountered: