Skip to content
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

Easy way to swap a vector out of the heap for non-aliased use #43

Open
jorendorff opened this issue Sep 1, 2017 · 0 comments
Open

Easy way to swap a vector out of the heap for non-aliased use #43

jorendorff opened this issue Sep 1, 2017 · 0 comments

Comments

@jorendorff
Copy link
Owner

This might be a useful hack, at least in the short term.

For example, in Scheme, (write-bytevector vec port) needs to call writer.write(buf) on some buffer. But it's unsafe to create a reference to the actual buffer in vec, because the vector has interior mutability: it could be aliased, and all aliases have write access.

As a hack, write-bytevector could momentarily swap the buffer out of the in-heap Vec, so that it "owns" the buffer and can safely pass it to .write(). The in-heap Vec would be momentarily empty. On success or failure, write-bytevector would swap the buffer back into the heap. Hokey but at least it's not a copy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant