Using shared memory instead of marshalling for C++ native plugins in Unity?

by Jon Koelzer   Last Updated October 09, 2019 03:13 AM - source

So I'm a C++ developer who has been playing with C# for a week or two in order to get acquainted with Unity, and I'm curious about the marshalling process used to transfer data for use in C++ native plugins. From what I can tell, the general consensus is that while using effective C++ plugins can be a performance increase for computation-heavy tasks, the marshalling process of transferring data can be significantly slower than the potential gains provided by the C++ flexibility.

I'm familiar with how shared memory works in C++ and it appears C# has the functionality required to use the buffers as well. From what I understand, the process of marshalling is slow due to copying, creating buffers and transferring chunks from one memory segment into another. Even though there's the problem of cache coherency when operating in shared memory, it may be less than the cost incurred by marshalling. I'm sure I'll have to do some experimenting.

Does anyone have thoughts or experience with using shared memory or marshalling in Unity who could weigh in on the question?

Tags : unity c# c++ memory


Related Questions


Memory is not getting freed on Destroy()

Updated March 01, 2018 08:13 AM

Manual Garbage Collection in Unity C#

Updated May 08, 2019 06:13 AM