dart-lang / dart-lang/native

Expose array data as pointer

Open
#411 4 comments 2 reactions 0 assignees View on GitHub
package:ffigen waiting-on-dart-ffi
Dominant language
Dart
Stars
275
Forks
144
Avg merge
2d 10h
Merged PRs (30d)
47

Description

Consider the aiString structure in [Assimp](https://github.com/assimp/assimp/blob/master/include/assimp/types.h#L384):
```
struct aiString {
uint32_t length;
char data[1024];
};
```

While the ArrayHelper, that is generated for the data, does offer [] and []= operators for accessing and manipulating the data at each index one by one, it seems like it would be more useful to expose the array data as a pointer:

```
class aiString extends Struct {
@Uint32()
int length;

Pointer get data => Pointer.fromAddress(addressOf.address + sizeOf());
}
```

[Int8Pointer](https://api.dart.dev/stable/2.9.1/dart-ffi/Int8Pointer.html) would not only offer the same operators, but would also let you have the data as a typed list view too. This struct here is extremely simple, though. Things might get hairy if there are holes/padding involved.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.