C++/VB - setting LFH (low fragmentation heap) on handles returned by getprocessheaps()

Asked By ted
16-Feb-08 04:49 AM
I'm running this simple C program (see below, compiled with cl.exe
version 14.00, XP SP2) and see the following  output:

Number of heaps returned by GetProcessHeaps() = 4
Heap 0: Succeeded (1) setting LFH
Heap 1: Succeeded (1) setting LFH
Heap 2: Failed (0) setting LFH, error = 31
Heap 3: Succeeded (1) setting LFH

Q: What are these 4 heaps? Do they have names (and how can I get the
names)?

Q: Which one corresponds to the one used by malloc()?

Q: Why does Heap 2 fail?



int main()
{
HANDLE aHeap[101] ;
ULONG HeapFragValue = 2 ;
BOOL retval ;
DWORD ii, nHeaps ;

nHeaps =(int)GetProcessHeaps( 100, aHeap ) ;     printf( "\nNumber
of heaps returned by GetProcessHeaps() = %d", nHeaps ) ;
for ( ii = 0 ; ii < nHeaps ; ii++ )
{
retval = HeapSetInformation( aHeap[ii],
HeapCompatibilityInformation,
&HeapFragValue,
sizeof(HeapFragValue) ) ;
if ( retval != 0 )
{
printf( "\nHeap %d: Succeeded (%d) setting LFH",
ii, retval ) ;
}
else
{
printf( "\nHeap %d: Failed (%d) setting LFH, error
= %d", ii, retval, GetLastError() ) ;
}
}

return 0 ;
}
XP
(1)
HeapFragValue
(1)
GetLastError
(1)
HeapAlloc
(1)
NHeaps
(1)
AHeap
(1)
B290154476a4425c
(1)
Getprocessheaps
(1)
  Alex Blekhman replied...
15-Feb-08 05:18 PM
I don't know what are these heaps, but heaps don't have names,
AFAIK.


The one with the handle equal to the value returned by
`_get_heap_handle' CRT function.


Probably it has some features incopatible with LFH. For example,
it could be created with `HEAP_NO_SERIALIZE' flag, as mentioned in
MSDN.

Alex
  Abhishek Padmanabh replied...
17-Feb-08 10:19 AM
HeapQueryInformation gives info about what the specific heap is. See
here - http://msdn2.microsoft.com/en-us/library/aa366703(VS.85).aspx
HeapInformation could be 0, 1 or 2. See details at the above page.


The standard heap (for which HeapInformation is 0) would be the one
where from you get the allocations, but I believe it depends on the
runtime to decide which one would be better from performance point of
view but I am sure of this. To allocate from specific heaps you would
make calls to HeapAlloc (and functions of that family).



To understand why heap 2 failed to set up as LFH, you would need to
know what heap that is and if setting it as LFH makes sense.
  Alex Blekhman replied...
16-Feb-08 01:32 PM
This is incorrect. HeapInformation = 0 does not automatically mean
that the heap is used by CRT. You should get CRT heap's handle by
calling `_get_heap_handle'.

Alex
  Abhishek Padmanabh replied...
17-Feb-08 10:20 AM
Actually, I missed a "not" before sure. :) Thanks for correcting me.
But, isn't the standard heap the one from which the allocations would
be done? I mean, one could change the heap info of standard heap to an
LFH but unless that is done, _get_heap_handle should return the same
heap as GetProcessHeap and that would be the same as the heap with HI
as 0 returned from GetProcessHeaps (considering heap info has not been
played around with). No?
  Alex Blekhman replied...
17-Feb-08 07:01 AM
Actually, I don't know whether there exists "standard" heap at
all. I think that CRT is free to choose a heap to use or to create
its own. I tried the code form this post:

http://groups.google.com/group/microsoft.public.win32.programmer.kernel/msg/b290154476a4425c

It reveals that there are at least two heaps with HeapInformation
= 0. One of them is indeed CRT heap.


I can't neither confirm nor refute that since I never heard about
this requirement. I always thought that CRT can use any heap it
sees fit.

Alex
Create New Account
help
0f, &mesh, NULL); Win32 DirectX Graphics Discussions D3DXMatrixLookAtLH (1) D3DXMatrixRotationY (1) D3DXCreateCylinder (1) OnD3D9FrameRender (1) XP (1) IDirect3DDevice9 (1) DrawIndexedPrimitive (1) UnlockVertexBuffer (1) [Please do not mail me a copy of M, T1836%T<FEX5')A;G-L871I;VXH)FUA = % = O<FQD+#$P+C!F+# N, &8L, "XP M9BD[#0H)<&0S9$1E = FEC92T^4V5T5')A;G-F;W)M*"!$, T144U]73U), 1"PF C P, # P, #LL"B @.38N, S Y.38W.RTW, 2XR, 3<W, 3([ M, "XP, # P, # [+ H@("TY-BXS, #DY-C<[-S$N, C$W-S$R.S N, # P Y, 3$W.RP*(" M M.38N, S Y.38W.RTW, 2XR, 3<W, 3([, "XP, # P, # [+ H@(#DV+C, P.3DV-SLM M-S$N, C$W-S$R.S CLP+C P, # P, #LL"B @+3DV+C, P.3DV-SLW, 2XR, 3<W, 3([, "XP, # P M, # [+ H@("TY-BXS, #DY-C<[-S$N, C$W-S$R.S$Q C0S.3$Q-SLL"B @+3DV+C, P.3DV-SLW M, 2XR, 3<W, 3([, "XP, # P, # [+ H@("TY-BXS, #DY-C<[+3<Q+C(Q-S<Q, CLQ M, 3 3@L, "PQ.3LL"B @, SLQ.2PV+#$X.SL*"B @ M365S:$YO<FUA;', @('L*(" @-CL*(" @, "XP, # P, # [, "XP, # P, # [+3$N M, # P, # P.RP*(" @, "XP, # P, # [, "XP, # P, # [, 2XP, # P, # [+ H@(" P
Refresh network connections? C++ / VB I maintain an XP-XP VPN connection between home and work. It's set to "redial if line is dropped I don't mean open the window and simulate F5.) Thanks. - - - Vince Win32 Networks Discussions XP (1) VPN (1) Vince (1) Disfunctional (1) Window (1) Redial (1) Icon (1) may be ipconfig' options. c: \ > ipconfig / renew YourConnectionName ali keywords: Refresh, network, connections? description: I maintain an XP-XP VPN connection between home and work. It's set to redial if line is dropped
happens? And if I click, it does not do anything also. Win32 DirectX Graphics Discussions XP (1) Ghz (1) E871E169F96 (1) Notebook (1) 38P.S (1) Dxut (1) Bits (1) TME C!F M+" P+C!F+"TS, "XP9B I.PT*(" @($0S1%A614-43U(S('95<%9E8R@@, "XP M9BP@, 2XP9BP@, "XP9B I.PT*(" @($0S1%A-051225A!, 38@;6%T5FEE = SL- M"B @("!$, T1836%T<FEX3&]O P+C P, # P, #LP+C P, # P M, #LP+C P, # P, #LL"B @, "XP, # P, # [, "XP, # P, # [, "XP, # P, # [+ H@ M(# N, # P, # P.S N, # P, # P.S N, # P, # P.RP P+C P, # P, #LP+C P M, # P, #LP+C P, # P, #LL"B @, "XP, # P, # [, "XP, # P, # [, "XP, # P, # [ M+ H@(# N, # P, # P.S N, # P, # P.S N, # P, # P.RP
Vista C++ / VB I have a program that is 32-bit and runs fine on XP, XP Pro and 2000. It has mainly VB 6 and C code. The application installs on compatible with abomination known as Vista? Thanks. VB Vista Compatibility Discussions Vista (1) VB (1) XP (1) Database (1) Adminstrator (1) Windows (1) ActiveX (1) Faral (1) Have you tried right The application installs on Vista but will not run. It installs and runs fine on XP, XP Pro and Windows 2000. It is a 32-bit app in VB6 with some C 3D ire = 3D I am using SEAU as the install program. It installs fine on XP and 2000. I wonder if I can give the permission to read / write to the for it? - Kev I am using SEAU as the install program. It installs fine on XP and 2000. I wonder if I can give the permission to read / write to the on, Vista description: I have a program that is 32-bit and runs fine on XP, XP Pro and 2000. It has mainly VB 6 and C code. The application installs