Memory Compaction....


I am basically writing a simple program which asks like 100KB from the system and then, we have to do the memory management of this 100KB. like writing a allocate function, a deallocate function using best-fit, worst-fit etc.

But about the compaction part, i am not exactly getting it. (in compaction i have to remove the fragmented parts, i.e move all allocated blocks to one end) how to preserve the pointers...... anyway? i read about handlers and smart pointers.. but didn't get anything.

So please if possible guide me, like in what ways i could overcome this compaction part. any links to some information would be in great use.

A highly useful book in general would be The C Programming Language by K and R. They've included many useful explanations from a one-line string copier to this exact problem.

Apparently the idiom is that contiguous unused portions would be made into 'blocks' with headers holding data on their own size, and a pointer to the next one, the last pointing to the first. You may as well read their explanation as it's apparently of how things are actually done in Unix.
Topic archived. No new replies allowed.