sharptooth
sharptooth

Reputation: 170489

Is it possible to compact the VC++ runtime heap?

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

Upvotes: 0

Views: 1063

Answers (2)

Steve Townsend
Steve Townsend

Reputation: 54158

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.

Upvotes: 2

Timo Geusch
Timo Geusch

Reputation: 24351

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.

Upvotes: 2

Related Questions