[C#] GetByKey needs an allocation-free overload
CTVjweiss opened this issue · comments
I'm using Flatbuffers in C# because I want an allocation free way of accessing my data. However, the current implementation of GetByKey()
has only one pathway that takes in a string
and converts it to a newly allocated byte[]
in the generated __lookup_by_key
function.
In my opinion this goes against the fundamental design principles of FlatBuffers of minimizing allocations whenever possible. I think it would be pretty easily fixed doing one of the following:
- Allow the caller to pass in an ArraySegment or a byte[] with offset and length that already points to the UTF8 encoded string.
- Add a byte[] parameter that defaults to null for
GetByKey()
that will be used for encoding to UTF8 for the binary search. If passed in, rely on the caller having passed a large enough byte array to the conversion to use the UTF8.GetBytes() function that writes to an existing array.
Feel free to submit a PR for this.
This issue is stale because it has been open 6 months with no activity. Please comment or label not-stale
, or this will be closed in 14 days.
This issue was automatically closed due to no activity for 6 months plus the 14 day notice period.