I have a C++ program that benchmarks various algorithms on input arrays of different length. It looks more or less like this:

# (1)
for k in range(4..20):
  # (2)
  input = generate 2**k random points
  for variant in variants:
    benchmark the following call
    run variant on input array
  # (3)


Is it possible to reset the whole heap management at (2) to the state it had at (1)? All memory allocated on the heap that was allocated during the program is guaranteed to be freed at (3).

I am using g++ 4.3 on Linux.

Edit: I understand that there is no real garbage collection in C/C++. I want to force the memory allocation to join adjacent empty chunks of memory it has in its free list at (2).


Question: Ubuntu dual boot OS crashed my computer. Now my computer won't boot. Please Help
Answer: I believe I've been plagued with your problem once or twice before. Make sure that your BIOS is set to use the optical or thumb drive first.  Its common to forget to set this feature. You should at least be able to access your BIOS screen if you know the key(s) that will launch this utility.  

Insert your Ubuntu disk else Windows disk and recover. Note that Windows does not see Ubuntu drives natively at all.  If none of this works for you then try another Hard drive but make sure to disconnect the one you cannot boot from.  Install. Now install the other drive as a slave and BIOS to make sure your computer boots off the disk you just installed the OS to. 

Keep in mind that if you install Ubuntu first, Windows will likely wipe out GRUB-your boot loader.  If you get everything working please report back to tell us on how you battled through it for those whom might have similar issues.  I wish you luck with your adventure. :P