Question

My current work-around is to, from C#, get the size of the vector using:

[DllImport("BridgeInterface.DLL", EntryPoint = "#46", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl]
private static extern int GetVectorSize();

where BridgeInterface.dll is a C++ bridge interface between my C++ and C# code. I then marshal each vector element using:

[DllImport("BridgeInterface.DLL", EntryPoint = "#47", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl]
private static extern double GetVectorElement(int index);

Is there a way to marshal the entire vector using a single call into C++?

No correct solution

OTHER TIPS

std::vector<>, per the standard, must reside in continuous memory space. So all your doubles are in one memory chunk so it can be marshalled as a single memory buffer (take the pointer to first element and do size() * sizeof(double) for the length of the buffer). After that it's reduced to the case of marshalling an array of doubles and I found this post on explaining how (with and without copying to C# memory space).

Using a DataStructure with fixed length will help you get rid of the Length Check.

3D Vector structure from c++ to C#

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top