Kartlee

2011-01-19 19:25:00 UTC

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

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