markus3000
Programmer
- Aug 24, 2010
- 9
When I run the code below in builder 6, it outputs that before the allocation of int * n = new int[10000000], there are 6 heaps, and after there are 6 heaps, and they are the same sizes as before the allocation.
When I run this code in MSVS C++ 2008, there are four heaps, and one of them grows by 40MB after the allocation..
what's going on?
thanks!
void Dump_Blocks_In_All_Heaps()
{
//get all the heaps in the process
HANDLE heaps [100];
DWORD c = ::GetProcessHeaps (100, heaps);
const HANDLE default_heap = ::GetProcessHeap();
for (unsigned int i = 0; i < c; i++)
{
//query the heap attributes
ULONG heap_info = 0;
SIZE_T ret_size = 0;
if :HeapQueryInformation(heaps, 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, &entry) )
{
cbtot += entry.cbData;
}
printf (" Allocated entry %d: size: %d, overhead: %d.\n", ++count, cbtot, entry.cbOverhead);
}
}
}
int main(int argc, char* argv[])
{
_HEAPINFO __entry;
_heapwalk( &__entry);
int k = _heapmin();
int k2 = _heapchk();
Dump_Blocks_In_All_Heaps_Orig();
int * n = new int[10000000];
for (int i=0; i<1000000; i++)
{
n = i;
}
int b = n[10000];
Dump_Blocks_In_All_Heaps_Orig();
}
When I run this code in MSVS C++ 2008, there are four heaps, and one of them grows by 40MB after the allocation..
what's going on?
thanks!
void Dump_Blocks_In_All_Heaps()
{
//get all the heaps in the process
HANDLE heaps [100];
DWORD c = ::GetProcessHeaps (100, heaps);
const HANDLE default_heap = ::GetProcessHeap();
for (unsigned int i = 0; i < c; i++)
{
//query the heap attributes
ULONG heap_info = 0;
SIZE_T ret_size = 0;
if :HeapQueryInformation(heaps, 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, &entry) )
{
cbtot += entry.cbData;
}
printf (" Allocated entry %d: size: %d, overhead: %d.\n", ++count, cbtot, entry.cbOverhead);
}
}
}
int main(int argc, char* argv[])
{
_HEAPINFO __entry;
_heapwalk( &__entry);
int k = _heapmin();
int k2 = _heapchk();
Dump_Blocks_In_All_Heaps_Orig();
int * n = new int[10000000];
for (int i=0; i<1000000; i++)
{
n = i;
}
int b = n[10000];
Dump_Blocks_In_All_Heaps_Orig();
}