Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Unmanaged Code

suburbanmtsuburbanmt Posts: 12Member
Hi,

I have a linked list which is built using unmanaged code. Is there a way in which I can store a non-primitive object such as a class instance? What i want is to be able to store an instance of Class1 for example in the list and than read the instance from the list.

Thanks

Comments

  • tsagldtsagld Posts: 621Member
    I am not sure there is a way, but if there were, it is probably extremely dangerous. So there probably isn't.
    The thing is that the Framework cannot keep track of references stored in unmanaged code. So there is a great risk that the Framework's garbage collector destroys the instance of your class while your unmanaged linked list still holds a reference to it.
    Reading the instance back from the list and using it will then result in disaster.


    : Hi,
    :
    : I have a linked list which is built using unmanaged code. Is there a way in which I can store a non-primitive object such as a class instance? What i want is to be able to store an instance of Class1 for example in the list and than read the instance from the list.
    :
    : Thanks
    :


    Greets,
    Eric Goldstein
    www.gvh-maatwerk.nl

  • suburbanmtsuburbanmt Posts: 12Member
    [b][red]This message was edited by suburbanmt at 2006-2-13 11:5:33[/red][/b][hr]
    The problem is that the application i'm developing is quite dependent on performance, so using an arraylist for the job wouldn't be that efficient. Do you have any suggestions regarding any other available data structures?

    Thanks for your help


    : I am not sure there is a way, but if there were, it is probably extremely dangerous. So there probably isn't.
    : The thing is that the Framework cannot keep track of references stored in unmanaged code. So there is a great risk that the Framework's garbage collector destroys the instance of your class while your unmanaged linked list still holds a reference to it.
    : Reading the instance back from the list and using it will then result in disaster.
    :
    :
    : : Hi,
    : :
    : : I have a linked list which is built using unmanaged code. Is there a way in which I can store a non-primitive object such as a class instance? What i want is to be able to store an instance of Class1 for example in the list and than read the instance from the list.
    : :
    : : Thanks
    : :
    :
    :
    : Greets,
    : Eric Goldstein
    : www.gvh-maatwerk.nl
    :
    :



  • suburbanmtsuburbanmt Posts: 12Member
    Tx, my problem is that the type is unknown as it is dynamic so I want the objects stored as OBJECT so that I can typecast them when I retrieve them from the list. What I want to do is as follows :

    1) I have an object of unknown type

    2) Store it in linked list (unmanaged code)

    3) Retrieve it from the list and type cast it
Sign In or Register to comment.