I'm transfering data between c++ and c# and I really need to have value-type arrays or list to pass the data directly. I don't mind them being a const expression. Is there a way to have an array which would behave like a c# struct or like a c++ std::array?
Edit: In the worst case i can use std::vector but i would prefer std::array because i really care about performance
If you're talking about arrays of primitive types (
byte,int, etc.) then marshalling between C# and C++ is quite simple usingfixed:Note this requires use of the
unsafeoption when compiling.The same works for
int,uint,short,ushort,float,double,long, andulong.You MUST use the pointer on the C++ side immediately and either copy it to a native buffer or be done with it before returning. The point of
fixedis to make sure the memory isn't GC'd or moved while control is inside thefixedblock.