gircore / gir.core

A C# binding generator for GObject based libraries providing a C# friendly API surface
https://gircore.github.io/
MIT License
299 stars 28 forks source link

Verify usage of Span / ReadOnlySpan #646

Open badcel opened 2 years ago

badcel commented 2 years ago

Span / ReadOnlySpan can potentially improve runtime behaviour as it avoids memory allocations.

Is there any documentation explaining benefits and / or common use cases?

Lehonti commented 1 year ago

I second this. I already know of a project that could benefit from this feature

https://github.com/PintaProject/Pinta

Pinta often uses byte arrays for image operations. Generated methods in the C# bindings of several libraries that are used by the project only accept regular C# arrays that are allocated on the heap. By accepting Span<> and ReadOnlySpan<> we would be able to allocate more things on the stack, improving efficiency.

badcel commented 1 year ago

I think this issue is more or less resolved since 0.4.0 as span is used for primitive data type arrays.

The only thing I saw while checking the tests is that it is not explicitly tested that the signature expects a span: this should be added to the tests.

See release 0.4.0