Ok, first of all I'm not sure if this is the correct forum for this question or not. But hopefully someone can help me or at least point me in the direction of the forum this belongs.
First of all, I am using C++, however it's managed C++ or visual C++, or whatever microsoft calls it. I'm using MSVS2005, and working on a Windows Forms Application project from the C++ projects tab. I'm pointing this out because apparently the syntax used in these projects is similar to C#, and I want to avoid that misunderstandin g.
Unfortunately the only class I've had on these types of projects used MSVS2003, which used a rather different set of syntax than 2005, so I've basically been piecing together what I can and teaching myself. 2005 uses the ^ character as a handle or whatever for managed objects. Up until, based on what I've seen of it, I've thought of this character (and the handles it creates) sort of like pointers (that is creating a reference to an object rather than working directly with the object).
Anyways, the problem I've run into is that I defined a managed class (public ref class), and need to create a linked list of these objects. My first thought was instead of trying to figure out the ins and outs of a prewritten linked list, I'd make my own linked list class with specifically the functionality I want/need. Unfortunately despite the similarities, these object handles are not pointers, which ruined my plans. For one thing I found that I can't set them to NULL or 0, nor can I delete them.
So basically I'm looking for any advice on what to do. The functionality I need is as follows: I need to know if the list is empty, I need to be able search the list to see if a specific instance of an object is in the list, I need to be able to insert objects into the list according in a sorted order (according to the < operator), and I need to be able to traverse the list from beginning to end to call the ToString() function of each object in the list (my original method was going to call the ToString of the first object and then remove the first object until the list was empty). And I'll need to be able to empty the list.
I realize I could probably jerry-rig a sort of linked list where I don't delete nodes, and just drop references to the earlier nodes, but I'm not sure how good of an idea this would be memory-wise. I imagine as a managed type, that it might not be a bad thing, that the garbage collector may handle the deletion for me, but given that I may create as many as 615 objects at a go, I'd rather not risk it until I'm sure.
Any help would be appreciated.
First of all, I am using C++, however it's managed C++ or visual C++, or whatever microsoft calls it. I'm using MSVS2005, and working on a Windows Forms Application project from the C++ projects tab. I'm pointing this out because apparently the syntax used in these projects is similar to C#, and I want to avoid that misunderstandin g.
Unfortunately the only class I've had on these types of projects used MSVS2003, which used a rather different set of syntax than 2005, so I've basically been piecing together what I can and teaching myself. 2005 uses the ^ character as a handle or whatever for managed objects. Up until, based on what I've seen of it, I've thought of this character (and the handles it creates) sort of like pointers (that is creating a reference to an object rather than working directly with the object).
Anyways, the problem I've run into is that I defined a managed class (public ref class), and need to create a linked list of these objects. My first thought was instead of trying to figure out the ins and outs of a prewritten linked list, I'd make my own linked list class with specifically the functionality I want/need. Unfortunately despite the similarities, these object handles are not pointers, which ruined my plans. For one thing I found that I can't set them to NULL or 0, nor can I delete them.
So basically I'm looking for any advice on what to do. The functionality I need is as follows: I need to know if the list is empty, I need to be able search the list to see if a specific instance of an object is in the list, I need to be able to insert objects into the list according in a sorted order (according to the < operator), and I need to be able to traverse the list from beginning to end to call the ToString() function of each object in the list (my original method was going to call the ToString of the first object and then remove the first object until the list was empty). And I'll need to be able to empty the list.
I realize I could probably jerry-rig a sort of linked list where I don't delete nodes, and just drop references to the earlier nodes, but I'm not sure how good of an idea this would be memory-wise. I imagine as a managed type, that it might not be a bad thing, that the garbage collector may handle the deletion for me, but given that I may create as many as 615 objects at a go, I'd rather not risk it until I'm sure.
Any help would be appreciated.
Comment