This is a mirror of official site: http://jasper-net.blogspot.com/

Windows 7 Heap Performance Analysis

| Thursday, August 5, 2010
Introduction

Heap performance impacts application performance, it is always a good thinking to consider if an application should have its own memory management framework for better performance. This article is to provide information for developers to make right decisions.

HeapPerf    

HeapPerf is a tool written with STL to measure performance. It reads a text file to count each words appeared in the text file. It overrides new and delete operators to get total amount time spent in new and delete. The code getting performance data is shown as below:

class CPerfCounter
{
public:
   CPerfCounter(long &sum) : _sum(sum)
   {
       QueryPerformanceCounter(&_startCounter);
   }
   
   ~CPerfCounter()
   {
       LARGE_INTEGER endCounter;
       QueryPerformanceCounter(&endCounter);
       endCounter.QuadPart -= _startCounter.QuadPart;
       if (endCounter.HighPart)
       {
           DebugBreak();
       }

       InterlockedExchangeAdd(&_sum, endCounter.LowPart);
   }
   
   LARGE_INTEGER _startCounter;

   long &_sum;
};

static int s_heapType = HEAPTYPE_OS;  
static int s_lazyHeapId = -1;
static long s_allocSum = 0;
static long s_freeSum = 0;

// STL uses global new/delete operators to allocate/free memories. needs
// to use STL in a static library
void* __cdecl operator new(size_t size)
{
   CPerfCounter pc (s_allocSum);

   void *pv;

Read more: Codeproject

Posted via email from .NET Info

0 comments: