Hi, everybody, Before I ask for help I'd like to say thanks for all your help you've been really helpful. If anyone has the algorithm for the compaction technique used in fragmentation please post it in the Code snippets it would be very helpful to me please!!

Ask a specific question, waffler
9 Years
Discussion Span
Last Post by mutah.87

thanks alot for tryingto help. I meant of a memory pool. If you can help me I would be very very thankful. Bye the way this homework is due in a week so please keep in touch.


I would expect memory allocation functions would use a couple of linked lists -- free memory list and used memory list. When a function calls new or malloc the free list is searched for the smallest block of memory available to satisfy the request. when found it will add the block to the used memory list. Then when delete or free() is called the block is put back into the free list. After some time the free list gets pretty fragmented.

The problem you face is how to scan the free list and combine nodes with adjacent blocks of memory. The structure of the node probably contains a pointer to the beginning of the block of memory and an unsigned int that is the amount of memory, something like this:

struct node
    void* block;
    unsigned int size;
    struct node* next;

With that you can use normal linked-list techniquest to iterate through the linked list and compare pointers ( thisNode->block + thisNode->size) is about the value of next->block.


Thank you so much that was very helpful. I read about you in the digest your background is very impressive. to tell you the truth I'm still a beginner and hoping to learn from people like you.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.