Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. ATL / WTL / STL
  4. STL list wrapped inside managed class

STL list wrapped inside managed class

Scheduled Pinned Locked Moved ATL / WTL / STL
csharpc++asp-netperformancequestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Flo Lee
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups