You are here:

C++/data structures


i actually need to make a project in which i have to make a programme in c++ in which i have to arrange free memory in a linked list.please give me some idea about this urgently

Dear Sourabh:

It is actually really simple.  new () and delete () do this automatically.  But you can develop a class that maintains a linked list of allocated unused memory and a separate linked list of allocated data (or memory or structures) currently being used.  

Whenever you need memory you call a routine that checks if there is any free memory in the linked list of unused memory.  If there is no more memory or none was stored yet, use new () to allocate a structure and put it on another linked list; you can call it the allocated link list of used memory.  

When you no longer need that structure put it on the linked list of unused memory.  When you need more memory check the linked list of unused memory and then get the structure off that linked list.  Before shutting down the program, use delete () to free both the linked list of unused memory and the linked list of used memory.

This is done by traversing each list and using delete () to free each element in each list.


All Answers

Answers by Expert:

Ask Experts


Titus B. Ledbetter, Jr.


C , MFC, Object Oriented, Artificial Intelligence


I have over ten years experience in the field of Computer Science, five years experience developing C/C++. I recently wrote a chess program using Object Oriented, C++, MFC.

Master's Degree Computer Science from Johns Hopkins

©2016 All rights reserved.