Discussion:
About Heap Allocator
(too old to reply)
Kartlee
2011-01-19 19:25:00 UTC
Permalink
Raw Message
Hi,

I compiled the following piece of code with Visual Studio 9.0 to
determine type of heap CRT use at runtime. In WindowsXP, I get the
heap type as look-asides whereas in windows 7 I get regular heap.

Here are my questions:

Is regular heap same as low fragmentation heap? Please explain if
there is any difference between the two.
Starting from Vista, I know the heap allocator has changed to LFH by
default. Is this the reason why I see 'regular heap' in Windows 7?
If I compile this piece of code with Visual Studio 10.0, I get the
heap type as LFH in Windows 7. Does VS 2010 changed the heap allocator
model of CRT? So if I run VS 2010 compiled code in windows xp, will I
get the heap type as LFH?
If you open a cmd shell in windows 7 and run Visual studio 9.0
compiled code with HOME env set c:\users\, I see the heap type is
changed to LFH? Why is this difference?
Code:

#include<stdio.h>
#include<stdlib.h>
#include <windows.h>

int main()
{
ULONG HeapFragValue = 2;
HANDLE crt_heap;
ULONG heap_info = 0;
SIZE_T ret_size = 0;
int i;

crt_heap = (HANDLE) _get_heap_handle ();
printf("%d\n", crt_heap);
if (HeapQueryInformation (crt_heap,
HeapCompatibilityInformation,
&heap_info,
sizeof (heap_info),
&ret_size))

{

switch (heap_info)
{

case 0:
printf ("Heap %d is a regular heap.\n");
break;
case 1:
printf ("Heap %d is a heap with look-asides (fast heap).\n");
break;
case 2:
printf ("Heap %d is a LFH (low-fragmentation) heap.\n");
break;
default:
printf ("Heap %d is of unknown type.\n");
break;
}
}

return 0;
}

-Karthik
opedroso
2011-01-20 14:24:34 UTC
Permalink
Raw Message
Hi Karthik,

On a Microsoft Windows 7 Ultimate Edition (build 7600), 64-bit, I
compiled with Dev2008 (whatheap.exe) and with Dev2010
(whatheap_2010.exe) and ran both it.
Both runs gave me these results (each using each DevStudio Tools Cmd
window with the correct environment.

Dev2008 Cmd:
p:\bin\src\whatheap>whatheap
6225920
Heap 0 is a regular heap.

Dev2010 Cmd:
p:\bin\src\whatheap>whatheap_2010.exe
3407872
Heap 0 is a regular heap.

I have heard that Windows Loader supposedely checks the header of the
executable and will set the environment according to its requirements
(for example, for a program compiled under XP, it will set up the
default XP heap settings for that process), but don't know for a fact
that this actually happens.

Either way, seems like we got different results from running on Win7.

Osiris
Loading...