STL list wrapped inside managed class
-
Dear all, I have the task to wrap a list inside a .NET wrapper, and actually after some heavy researching and editing, it seems to work, but I dont trust that I have understood all unmanaged issues correctly. First, I found I should add an operator overload and a copy constructor to my class:
RawCoil::RawCoil(const Core::RawCoil& pParam)
{
*this = pParam;
}RawCoil& RawCoil::operator=(const RawCoil &obj) { this->Id = obj.Id; return \*this; }
Is this correct? Then, there is the main list variable, which is used inside the unmanaged code. When is the memory allocated/freed, this I don´t understand:
list coils; //where is this object instantiated? automagically?
Another interesting questions. The List<> from .NET will arrive with new elements from time to time, and I have to synchronize it to the unamanged code:
int unmanageCoils(List^ managedCoils, list *unmanagedCoils)
{
unmanagedCoils->clear();
for(int i=0;iCount;i++)
{
Coil^ coil = managedCoils[i];
Core::RawCoil newCoil; //where is this object instantiated? automagically?
newCoil.Id = ManagedToSTL(coil->coilId); //string conversion
unmanagedCoils->push_back(newCoil);} return managedCoils->Count;
how is the memory allocation treated for the list elements? The thing is I want to prevent any leaking of memory, as I am normally only developing in C# and quite paranoid when I have to switch back to old times :) kind regards Florian