-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Some of the generated bindings return a pointer when it could return a ref (like how SDL.CreateSurfaceFrom
returns SDLSurface*
but SDL.DestroySurface
can take a ref SDLSurface
). It is safe to return a ref as the pointers are guaranteed to be pinned. Or, for async support, you can wrap the pointers in a struct and pass the pointer in the struct to the p/invoke.
Using the below methods, all pointers can be converted into a ref and vice versa
https://learn.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.unsafe.asref?view=net-6.0#system-runtime-compilerservices-unsafe-asref-1(system-void*)
https://learn.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.unsafe.aspointer?view=net-6.0
Additionally, I would also suggest changing the ref parameters to ref readonly parameters if possible (prevents having to write more code to support the current restricted overloads)
I understand that the goal is to keep a minimal bindings library, however adding new overloads to support non-unsafe code helps in writing significantly less code (and having to add unsafe everywhere)