2

I have a ref class that contains a pointer to an unmanaged class. the class has some basic types and also a vector of objects of another class. I would like to know the best way to get and set the vector from managed code. Will a memcpy between unmangedb objects be efficient or setting each member variable of unmanagedb?

for ex (assume the class is complete. I am writing what is relevant to the question)

Assume we already have a managed wrapped for struct UnmanagedB called B.

struct UnmanagedA
{
   int a;
   vector<UnmanagedB> list;
};

public ref class A : public System::IDisposable
{
public:
    // properties
    property System::UInt32 a
   {
       System::UInt32 get();
       void set(System::UInt32 value);
   }

   property array<B^>^ list
   {
       System::array<B^>^ get(); // what is the best way to set and get the vector
       void set(array<B^>^ value);
   }

private:
   UnmanagedA* obj1;
};
Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Sriram Subramanian
  • 2,623
  • 5
  • 32
  • 35

1 Answers1

0

This obviously won't be cleanly possible, since UnmanagedA contains a vector of UnmanagedB values, while A exposes an property of type array<B^>. If this is intended and not a typo, you will need to marshall the content of B^ into instances of UnmanagedB. Otherwise, let UnmanagedA hold a std::vector< B* > and take care of proper lifetime management.

Paul Michalik
  • 4,331
  • 16
  • 18