Markus
2010-09-07 15:38:12 UTC
Hi
After running the code below, the output to console indicates no heap growth
in any of the calling process' 8 heaps... surely the new allocation should
cause one of the heaps to grow by about 4x10000000B = 40 MB?
what's wrong?
#include <windows.h>
#include <malloc.h>
#include <stdio.h>
#pragma hdrstop
void Dump_Blocks_In_All_Heaps_Orig()
{
//get all the heaps in the process
HANDLE heaps [100];
DWORD c = ::GetProcessHeaps (100, heaps);
printf ("The process has %d heaps.\n", c);
//get the default heap and the CRT heap (both are among
//those retrieved above)
const HANDLE default_heap = ::GetProcessHeap();
//const HANDLE crt_heap = (HANDLE) _get_heap_handle ();
for (unsigned int i = 0; i < c; i++)
{
//query the heap attributes
ULONG heap_info = 0;
SIZE_T ret_size = 0;
if (::HeapQueryInformation (heaps [i], HeapCompatibilityInformation,
&heap_info, sizeof (heap_info), &ret_size))
{
PROCESS_HEAP_ENTRY entry;
memset (&entry, 0, sizeof (entry));
int count = 0;
int cbtot = 0;
while (::HeapWalk( heaps[i], &entry) )
{
cbtot += entry.cbData;
}
printf (" Allocated entry %d: size: %d, overhead: %d.\n", ++count,
cbtot, entry.cbOverhead);
}
}
}
#pragma argsused
int main(int argc, char* argv[])
{
//ConstructorDestructorMemleakTest();
Dump_Blocks_In_All_Heaps_Orig();
int * n = new int[10000000];
for (int i=0; i<1000000; i++)
{
n[i] = i;
}
int b = n[10000];
Dump_Blocks_In_All_Heaps_Orig();
}
Output is:
The process has 6 heaps.
Allocated entry 1: size: 1040907, overhead: 0
Allocated entry 1: size: 65488, overhead: 0.
Allocated entry 1: size: 64584, overhead: 0.
Allocated entry 1: size: 64896, overhead: 0.
Allocated entry 1: size: 261504, overhead: 0.
Allocated entry 1: size: 64446, overhead: 0.
The process has 6 heaps.
Allocated entry 1: size: 1040907, overhead: 0
Allocated entry 1: size: 65488, overhead: 0.
Allocated entry 1: size: 64584, overhead: 0.
Allocated entry 1: size: 64896, overhead: 0.
Allocated entry 1: size: 261504, overhead: 0.
Allocated entry 1: size: 64446, overhead: 0.
url:http://www.ureader.com/gp/1474-1.aspx
After running the code below, the output to console indicates no heap growth
in any of the calling process' 8 heaps... surely the new allocation should
cause one of the heaps to grow by about 4x10000000B = 40 MB?
what's wrong?
#include <windows.h>
#include <malloc.h>
#include <stdio.h>
#pragma hdrstop
void Dump_Blocks_In_All_Heaps_Orig()
{
//get all the heaps in the process
HANDLE heaps [100];
DWORD c = ::GetProcessHeaps (100, heaps);
printf ("The process has %d heaps.\n", c);
//get the default heap and the CRT heap (both are among
//those retrieved above)
const HANDLE default_heap = ::GetProcessHeap();
//const HANDLE crt_heap = (HANDLE) _get_heap_handle ();
for (unsigned int i = 0; i < c; i++)
{
//query the heap attributes
ULONG heap_info = 0;
SIZE_T ret_size = 0;
if (::HeapQueryInformation (heaps [i], HeapCompatibilityInformation,
&heap_info, sizeof (heap_info), &ret_size))
{
PROCESS_HEAP_ENTRY entry;
memset (&entry, 0, sizeof (entry));
int count = 0;
int cbtot = 0;
while (::HeapWalk( heaps[i], &entry) )
{
cbtot += entry.cbData;
}
printf (" Allocated entry %d: size: %d, overhead: %d.\n", ++count,
cbtot, entry.cbOverhead);
}
}
}
#pragma argsused
int main(int argc, char* argv[])
{
//ConstructorDestructorMemleakTest();
Dump_Blocks_In_All_Heaps_Orig();
int * n = new int[10000000];
for (int i=0; i<1000000; i++)
{
n[i] = i;
}
int b = n[10000];
Dump_Blocks_In_All_Heaps_Orig();
}
Output is:
The process has 6 heaps.
Allocated entry 1: size: 1040907, overhead: 0
Allocated entry 1: size: 65488, overhead: 0.
Allocated entry 1: size: 64584, overhead: 0.
Allocated entry 1: size: 64896, overhead: 0.
Allocated entry 1: size: 261504, overhead: 0.
Allocated entry 1: size: 64446, overhead: 0.
The process has 6 heaps.
Allocated entry 1: size: 1040907, overhead: 0
Allocated entry 1: size: 65488, overhead: 0.
Allocated entry 1: size: 64584, overhead: 0.
Allocated entry 1: size: 64896, overhead: 0.
Allocated entry 1: size: 261504, overhead: 0.
Allocated entry 1: size: 64446, overhead: 0.
url:http://www.ureader.com/gp/1474-1.aspx