Advertisement Jump to content

Archived

This topic is now archived and is closed to further replies.

Neen10do

Listlist and heaps

This topic is 5826 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

im creating a LinkList class that can hold dynamic amounts of game sprites. when the destructor is called (which would only be when the game is shut down) would i have to traverse the linkedlist in the destructor to deallocate all the memory and return it to the heap, or is automatically returned when the program shuts down? i code therefore i am.

Share this post


Link to post
Share on other sites
Advertisement
If you're talking about the kind of linked list that I'm thinking of, you can just loop through from the front until you reach the end (i.e. NULL) deleting the dynamically allocated memory (the nodes):

  
CList::~CList()
{
Node *temp = NULL;
while (front) // whilst front != NULL

{
temp = front; // save address

front = front->next; // advance pointer to next node

delete temp; // delete node

}
}


:::: Lektrix ::::
[ Google || ACCU || BarrysWorld || E-Mail Me ]

[edited by - Lektrix on February 8, 2003 6:42:21 AM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!