Skip to content

DirectBuffer - Support ArraySegment for underlying array #878

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 2 commits into from
Nov 17, 2021

Conversation

guigzzz
Copy link
Contributor

@guigzzz guigzzz commented Nov 16, 2021

What: Support ArraySegment for underlying array

Why: It's useful to be able to read an SBE message from a view (i.e. ArraySegment) on a big array of bytes, without copies. Currently, we'd have to slice the byte array, which results in a copy.

How: similar to the byte[] case, pin the ArraySegment's underlying buffer so the GC doesn't move it, then offset the created pointer by the ArraySegment offset so that we point to the right memory.

Testing: run unit tests locally with ./runtests

Note: The C# wrappers should really be re-written using structs and Spans, which would enable fast and memory efficient code while still being safe, which the current code is not. Then again, that's a non-trivial undertaking, so this will suffice for now :)

@guigzzz guigzzz marked this pull request as ready for review November 16, 2021 20:30
@mjpt777 mjpt777 merged commit afb62b5 into aeron-io:master Nov 17, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants