Heap questions - Low Frag Heap?



RichK
07-09-2005, 09:26 PM
Greetings,

We are trying to use the Low Fragmentation Heap under XP Embedded SP2. We
use the code:

ULONG ulHeapCompatibilityInformation ;
ulHeapCompatibilityInformation = 2;
if(HeapSetInformation(GetProcessHeap(),HeapCompatibilityInformation,&ulHeapCompatibilityInformation,
sizeof(ulHeapCompatibilityInformation))) {
OutputDebugString("Heap algorithm set to Low-fragmentation heap\n");
}
else
OutputDebugString("Heap algorithm NOT set to Low-fragmentation heap\n");

This always fails with GetLastError() returning a 31 (0x8007001f).

Afterwards, we do a HeapQueryInformation and the response is always 1.

Is the LFH valid in XPE?

Additionally, what is the maximum size of a heap? Our system seems to
generate 55 heaps shortly after starting, not sure where they are all coming
from. The main process heap runs out of memory after a few hours of running
and the system fails. We don't specify any heap sizes. Does a heap get
created for each thread? We have a lot of those that come and go. Also, how
does the type of heap get determined? When I do HeapQueryInformation each of
the heaps, some are type 0 and some type 1. None are type 2 (what we want).

Is there just a forum for Heap stuff?

Thanks
Rich.

KM
07-09-2005, 09:26 PM
Rich,

LHF support is definitely on XPe as the binaries (specifically, the kernel32.dll) are the same as on XP Pro.

Do you build and try debug or release binaries of the application that calls to the HeapSetInformation? The API would only work in
release mode.

Btw, do you use Winlogon in your image?
I think Winlogon may be required to use the user mode low heap fragmentation feature on XP/XPe. But I'd like to confirm that (never
tried that on XPe)

All the heap limitations on XPe in Win32 world are the same as on XP Pro.
You should direct all your question regarding Heap allocations to some Win32 development newsgroup.

Basically, the heap size is defined through last parameters of HeapCreate call. The heap's size is limited only by available memory
to the process.
For the default Heap that is created implicitly for your process you should use /HEAP switch of linker to specify the required size
(default = 1Mb). With the HEAP switch you specify the reserve and commit arguments.

--
Regards,
KM, BSquare Corp.


> Greetings,
>
> We are trying to use the Low Fragmentation Heap under XP Embedded SP2. We
> use the code:
>
> ULONG ulHeapCompatibilityInformation ;
> ulHeapCompatibilityInformation = 2;
> if(HeapSetInformation(GetProcessHeap(),HeapCompatibilityInformation,&ulHeapCompatibilityInformation,
> sizeof(ulHeapCompatibilityInformation))) {
> OutputDebugString("Heap algorithm set to Low-fragmentation heap\n");
> }
> else
> OutputDebugString("Heap algorithm NOT set to Low-fragmentation heap\n");
>
> This always fails with GetLastError() returning a 31 (0x8007001f).
>
> Afterwards, we do a HeapQueryInformation and the response is always 1.
>
> Is the LFH valid in XPE?
>
> Additionally, what is the maximum size of a heap? Our system seems to
> generate 55 heaps shortly after starting, not sure where they are all coming
> from. The main process heap runs out of memory after a few hours of running
> and the system fails. We don't specify any heap sizes. Does a heap get
> created for each thread? We have a lot of those that come and go. Also, how
> does the type of heap get determined? When I do HeapQueryInformation each of
> the heaps, some are type 0 and some type 1. None are type 2 (what we want).
>
> Is there just a forum for Heap stuff?
>
> Thanks
> Rich.

KM
07-09-2005, 09:26 PM
Forgot to mention.
Here is a pretty good presentation about LHF:
http://www.i.u-tokyo.ac.jp/ss/lecture/new-documents/Lectures/16-UserModeHeap/UserModeHeapManager.ppt.

And keep im mind that to use the LFH in your application, you have to call the HeapCreate or GetProcessHeap function to obtain a
handle to a standard heap (which is what you control with HEAP switch). Then call the HeapSetInformation function to enable the LFH.
If the call succeeds, memory is allocated and freed in the LFH when you call the heap API. Otherwise, the memory is allocated in the
standard heap.

--
Regards,
KM, BSquare Corp.


> Rich,
>
> LHF support is definitely on XPe as the binaries (specifically, the kernel32.dll) are the same as on XP Pro.
>
> Do you build and try debug or release binaries of the application that calls to the HeapSetInformation? The API would only work in
> release mode.
>
> Btw, do you use Winlogon in your image?
> I think Winlogon may be required to use the user mode low heap fragmentation feature on XP/XPe. But I'd like to confirm that
(never
> tried that on XPe)
>
> All the heap limitations on XPe in Win32 world are the same as on XP Pro.
> You should direct all your question regarding Heap allocations to some Win32 development newsgroup.
>
> Basically, the heap size is defined through last parameters of HeapCreate call. The heap's size is limited only by available
memory
> to the process.
> For the default Heap that is created implicitly for your process you should use /HEAP switch of linker to specify the required
size
> (default = 1Mb). With the HEAP switch you specify the reserve and commit arguments.
>
> --
> Regards,
> KM, BSquare Corp.
>
>
> > Greetings,
> >
> > We are trying to use the Low Fragmentation Heap under XP Embedded SP2. We
> > use the code:
> >
> > ULONG ulHeapCompatibilityInformation ;
> > ulHeapCompatibilityInformation = 2;
> > if(HeapSetInformation(GetProcessHeap(),HeapCompatibilityInformation,&ulHeapCompatibilityInformation,
> > sizeof(ulHeapCompatibilityInformation))) {
> > OutputDebugString("Heap algorithm set to Low-fragmentation heap\n");
> > }
> > else
> > OutputDebugString("Heap algorithm NOT set to Low-fragmentation heap\n");
> >
> > This always fails with GetLastError() returning a 31 (0x8007001f).
> >
> > Afterwards, we do a HeapQueryInformation and the response is always 1.
> >
> > Is the LFH valid in XPE?
> >
> > Additionally, what is the maximum size of a heap? Our system seems to
> > generate 55 heaps shortly after starting, not sure where they are all coming
> > from. The main process heap runs out of memory after a few hours of running
> > and the system fails. We don't specify any heap sizes. Does a heap get
> > created for each thread? We have a lot of those that come and go. Also, how
> > does the type of heap get determined? When I do HeapQueryInformation each of
> > the heaps, some are type 0 and some type 1. None are type 2 (what we want).
> >
> > Is there just a forum for Heap stuff?
> >
> > Thanks
> > Rich.
>
>


Heap questions - Low Frag Heap?