views:

105

answers:

2

Can I have the same effect as with HeapCompact() for the Visual C++ runtime heap? How can I achieve that?

+2  A: 

IIRC not without writing your own memory manager. It's also a non-trivial piece of work, especially if you expect to do more than just combining adjacent smaller empty memory blocks into larger ones.

Timo Geusch
In fact combining adjacent blocks is the only thing HeapCompact() does.
sharptooth
You'd have to *really* need to do this for there not to be a better idea.
Spike
+2  A: 

You can get a HANDLE for the CRT heap using _get_heap_handle, then call HeapCompact on it. Not sure whether this is supported/stable as I have not tried this myself. I imagine you would want to call HeapCompact in serialized mode to have any chance of this working.

If you are going to this trouble just call HeapSetInformation on the handle (per MDSN docs on _get_heap_handle) and let the built-in LFH handle compaction for you.

Steve Townsend