caught between managed and unmanaged C++
-
In unmanaged C++ code, I have a vector of a class of instances that contains a vector of instances of another class (which actually also contains a vector of instances of another class). public class1 { private: double xLocation; double yLocation; vector sub1; //methods, etc. } public Subclass1 { private: double zLocation; vector sub2; //methods, etc. } public Subclass2 { private: double value1; double value2; //methods, etc. } I get this all populated in unmanaged C++ code. However, I then need to get this to a C# front end via managed C++. Should I convert this structure in the managed file? Convert the vectors to ArrayLists? What is the best way to do this? Has anyone done this? Thanks for any help/advice.
-
In unmanaged C++ code, I have a vector of a class of instances that contains a vector of instances of another class (which actually also contains a vector of instances of another class). public class1 { private: double xLocation; double yLocation; vector sub1; //methods, etc. } public Subclass1 { private: double zLocation; vector sub2; //methods, etc. } public Subclass2 { private: double value1; double value2; //methods, etc. } I get this all populated in unmanaged C++ code. However, I then need to get this to a C# front end via managed C++. Should I convert this structure in the managed file? Convert the vectors to ArrayLists? What is the best way to do this? Has anyone done this? Thanks for any help/advice.
It is unclear exactly how you need to pass the vector data, whether anything needs to be modified in C#, and so forth. One question is whether you could re-implement all this in MC++ (or C#) from scratch to begin with. That is, populate ArrayLists from the get-go. If you have no choice but to pass unmanaged stuff to managed code, you will likely need to copy everything into managed (GC-collected) memory. If everything is largely primitive types (except the vectors, of course), then that shouldn't be too bad. If you need to pass values/changes back to unmanaged code, you will have to copy again. Obviously, it is best to minimise how much data must be marshaled back and forth between unmanaged and managed memory. If the "vectors" need to be dynamic within C#, then ArrayList seems like a reasonable choice, though performance will not be as good (if nothing else but because everything will have to be handled by pointers to the base Object class). If performance is not a major consideration, then go that way. If nothing needs to be modified (i.e., not dynamic) in C#, then __gc[] arrays are more efficient, and more flexible in MC++ than in C#. If you can be more specific about how the vectors need to be used, perhaps I could be more specific with any suggestions. I have been swimming in the regions between C++ and MC++ for quite a while now. Cheers