I came across an interesting Microsoft Support article on heap performance counters. Apparently there is a registry setting that enables heap counters on Perfmon. This allows users to profile various aspect of heaps in a process.
Perfmon.exe displays these counters when the following registry key is set:HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesPerfProcPerformance
In 2009, I wrote some test code to benchmark Low Fragmentation Heap (LFH). Recall that the original test is single-threaded program that randomly allocates and deallocates various size buffers a number of times.
With minor touch-ups, I customized the test code to run with two threads in parallel. So I kicked off the modified test and added a Heap Lock Contention counter on the main process heap.
I re-ran the test program to use LFH allocator (switchable through a command line argument). The LFH allocator results in 50% less contention compare to the default allocator in Window XP.
I could not get this counter to work properly under Window 7. Microsoft mentioned that only Windows Server 2003, Windows Vista, and Windows Server 2008 are enhanced.
If heap lock contention is a problem, Windows via C/C++ recommends to create a separate heap for allocation intensive classes with a custom new/delete operator.
LFH outperforms the default allocator under Window XP. The heap contention counter confirms my original test result in 2009.
Tools: Visual Studio 2008 (VC9), Boost 1.45, Window XP SP3 (32 bit)
The source program can be downloaded here.