Sunday, November 9, 2008

Heap Demo project

Heap Demo is a project designed to show the relationship between virtual and committed
memory during heap use. Using a contrived scenario, a stair-step growth of virtual
memory can be observed in perfmon.

Open a new cpp file in Visual Studio. copy and paste code from this post. compile the file it will create project for u. then u can proceed further

1. Start the HeapDemo application.
2. Open perfmon.
3. Add counters for Virtual Bytes and Private Bytes for the HeapDemo Process.
4. Change the scale for each counter to 0.0000001 (lowest value).
5. Press ENTER on the console for HeapDemo to start the allocations.
6. Watch the perfmon window as memory is allocated.

Note the stair step behavior of virtual memory. Each time the private bytes nears the amount
of virtual bytes reserved, the memory manager extends the heap by reserving more virtual
memory. Each time the heap is extended, it reserves twice as much as the previous reservation.

// Tthe entry point for the console application.


void Test();

int main(int argc, char* argv[])

return 0;

void Test()
int nCount = 0;
int nTotal = 0;
char c;

// scanf in here only to hold process in initial loaded state to set up PerfMon.
printf("Set up Process Object's Private and Virtual Bytes for Heapdemo.exe, then hit ENTER to start the test\n");

while(nTotal < 200000)
int (*i)[1024] = new int[100][1024];
nTotal += 100;
printf("Allocated: %d KB\n", nTotal);

printf("Hit any key to end the test and release all memory\n");

No comments:

Your Title