-
Notifications
You must be signed in to change notification settings - Fork 3.5k
C# support for directly reading and writing to memory other than byte[] #4886
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,6 +78,23 @@ public int __vector(int offset) | |
| return offset + bb.GetInt(offset) + sizeof(int); // data starts after the length | ||
| } | ||
|
|
||
| #if ENABLE_SPAN_T | ||
| // Get the data of a vector whoses offset is stored at "offset" in this object as an | ||
| // Spant<byte>. If the vector is not present in the ByteBuffer, | ||
| // then an empty span will be returned. | ||
| public Span<byte> __vector_as_span(int offset) | ||
| { | ||
| var o = this.__offset(offset); | ||
| if (0 == o) | ||
| { | ||
| return new Span<byte>(); | ||
| } | ||
|
|
||
| var pos = this.__vector(o); | ||
| var len = this.__vector_len(o); | ||
| return bb.ToSpan(pos, len); | ||
| } | ||
| #else | ||
| // Get the data of a vector whoses offset is stored at "offset" in this object as an | ||
| // ArraySegment<byte>. If the vector is not present in the ByteBuffer, | ||
| // then a null value will be returned. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this function maybe always be available, for backwards compatibility?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually never mind, the user has to explicitly enable ENABLE_SPAN_T so it is ok There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Given that this is a preprocessor directive, how would this surface to the user?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You will have to build the library with ENABLE_SPAN_T defined in much the same way to need to build the library with UNSAFE_BYTEBUFFER defined to get the performance benefits. |
||
|
|
@@ -93,6 +110,7 @@ public int __vector(int offset) | |
| var len = this.__vector_len(o); | ||
| return bb.ToArraySegment(pos, len); | ||
| } | ||
| #endif | ||
|
|
||
| // Get the data of a vector whoses offset is stored at "offset" in this object as an | ||
| // T[]. If the vector is not present in the ByteBuffer, then a null value will be | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is pretty awesome.