Closed tdmowrer closed 3 years ago
Thanks for reaching out. Happy to help investigate here.
For context -- everything FlatSharp does is based on Span<T>
. I've had reports of other Unity users using FlatSharp successfully in #125 as you mentioned.
Is the problem specifically with ReadOnlySpan<T>
, or does it affect both Span
and ReadOnlySpan
? This code definitely works in .NET Framework 4.7 (assuming you add a reference to System.Memory
).
everything FlatSharp does is based on
Span<T>
.
Thanks for the context -- good to know.
Is the problem specifically with
ReadOnlySpan<T>
, or does it affect bothSpan
andReadOnlySpan
? This code definitely works in .NET Framework 4.7 (assuming you add a reference toSystem.Memory
).
The only problematic generated code that I saw involved a ReadOnlySpan<T>
. I would expect Span
and ReadOnlySpan
to have the same problem, but the compiler did not produce them from my schema. I agree it should be possible to add System.Memory
for use in Unity.
Thanks for the quick response!
Just to clarify -- are you unblocked? If adding System.Memory fixed your issue, I can add that to the docs.
I decided not to go with FlatSharp and just use Google's FlatBuffers C# implementation, so I never got further than this.
One reason for this that may be of interest is that Google's implementation uses C# structs for the types generated from the schema, while FlatSharp seems to prefer use of classes. I (and Unity users in general) try to avoid per frame GC allocations. Looks like this was considered in https://github.com/jamescourtney/FlatSharp/issues/164.
Sounds good -- thanks for letting me know. Flatsharp does everything by inheritance, which isn't a thing with structs. I'm not sure how Unity's GC works, but I at one point had a branch of FlatSharp that did offer "struct structs", and it performed worse in my testing than classes. However, I'm not a Unity expert by any stretch, so YMMV. Cheers!
I am using FlatSharp in the context of Unity, which limits me to .NET 4.7 or .NET Standard 2.0.
This schema:
Compiled with the net47 compiler generates C# code containing a
ReadOnlySpan
:Which is incompatible with the .NET 4.7 framework. Is this expected?
Note this only happens when the fixed length array is of a primitive type (e.g.,
float
). Fixed length arrays of user-defined types do not have this problem.Possibly related thread: https://github.com/jamescourtney/FlatSharp/issues/125