Skip to content

Make dart:ffi Pointer an extension type over int #60722

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

Closed
alexmarkov opened this issue May 13, 2025 · 1 comment
Closed

Make dart:ffi Pointer an extension type over int #60722

alexmarkov opened this issue May 13, 2025 · 1 comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. library-ffi

Comments

@alexmarkov
Copy link
Contributor

Currently Pointer from dart:ffi is a heap object. It takes 3 words of memory (object header, address value and type arguments). Accessing pointer involves an extra indirection - we need to read an address value from the Pointer object before address value can be used to access pointed memory or do address arithmetic.

If large number of Pointer objects are used to point to small structs, the overhead of Pointer can be comparable to the amount of useful memory being addressed, which makes Pointer pretty much useless for building off-heap data structures.

With extension types, it is possible to make Pointer a zero-cost abstraction over address value (represented as int) and avoid these overheads: we would not need a heap object at all (unless int is boxed), Pointer would take only 1 word on 64-bit systems and it would not need an extra indirection when accessing address.

/cc @dcharkes @mraleph

@alexmarkov alexmarkov added area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. library-ffi labels May 13, 2025
@dcharkes
Copy link
Contributor

👍

Duplicate of:

See the comments there about 32-bit pointers. Let's discuss on that issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. library-ffi
Projects
None yet
Development

No branches or pull requests

2 participants