cosyneco / MediaPipe.NET

Pure .NET bindings for Google's MediaPipe.
MIT License
97 stars 18 forks source link

Replace all `Marshal` operations with `unsafe` ones #7

Closed Speykious closed 2 years ago

Speykious commented 2 years ago

Marshalling in C# can be extremely slow. Thus, now that .NET 6 has come with NativeMemory, it is preferrable to use unsafe operations as much as we can.

One first step has been done: instead of using Unity's NativeArray for the ImageFrame class, we have used a raw byte* pointer and the tests worked flawlessly.

Nothing has been benchmarked so far, but we can infer from how marshalling works that using unsafe will benefit us in the long run.