News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

GetProcessHeap ?

Started by K_F, November 07, 2014, 07:31:36 PM

Previous topic - Next topic

K_F

Maybe I'm blind but I cannot see (MSDN) where to de-allocate the heap handle returned by the GetProcessHeap function.
MSDN says that you shouldn't use HeapFree, HeapDestroy..etc.. but doesn't say what you can use  :icon_eek:

I'm placing this in the WinProc's WM_Close message...

Maybe the process termination does this automatically ??
'Sire, Sire!... the peasants are Revolting !!!'
'Yes, they are.. aren't they....'

Gunther

Hi Tony,

Quote from: K_F on November 07, 2014, 07:31:36 PM
Maybe the process termination does this automatically ??

yes it does by the termination of the process, I think. I couldn't find nothing other as you found.

Gunther
You have to know the facts before you can distort them.

Zen

#2
VAN/K_F,
Each process has at least one heap: the default process heap. The default heap is created at process startup and is never deleted during the process's lifetime.
Look at the example mentioned at the bottom of the GetProcessHeap documentation: Getting Process Heaps.
They just completely ignore the HANDLE value. I don't think it makes any difference,...but, I just set the HANDLE value equal to zero when I'm finished allocating and using memory from the Default Process Heap.
...You could, of course, call CloseHandle, but the documentation doesn't list the Default Process Heap as an object that CloseHandle will close the handle to. In general, CloseHandle invalidates the specified object handle, decrements the object's handle count, and performs object retention checks. After the last handle to an object is closed, the object is removed from the system.
It seems that all the documentation that I've read will recommend calling CloseHandle on a handle that is returned from a Windows API, if it is necessary to decrement the reference count on the handle.
Heap Functions, MSDN

K_F

Ja, I follow what you're saying, which is why I thought it was destroyed on the process termination.

The thing that made me think was that, if every process had a default heap, why would GetProcessHeap return a NULL, if it's only a handle.
:biggrin:
'Sire, Sire!... the peasants are Revolting !!!'
'Yes, they are.. aren't they....'

Zen

VAN/K_F,   
Quote from: VANThe thing that made me think was that, if every process had a default heap, why would GetProcessHeap return a NULL, if it's only a handle.
Hell if I know,...I've had that happen on occasion too,...It seems like one of those functions that would never fail,...:dazzled:
...By the way,...that first line of my post:
Each process has at least one heap: the default process heap. The default heap is created at process startup and is never deleted during the process's lifetime. is quoted from Windows Internals. The author never mentions the HANDLE value returned from GetProcessHeap.

K_F

Thanks.. I sort of gathered that much.
One could deduce that GetProcessHeap.. is the default heap handle, and we have no control over, except for using for HeapAlloc functions, etc..
:t

'Sire, Sire!... the peasants are Revolting !!!'
'Yes, they are.. aren't they....'

TouEnMasm

QuoteOne could deduce that GetProcessHeap.. is the default heap handle
And it is called like that by MSDN  (search words:Msdn Heap memory)
http://msdn.microsoft.com/en-us/library/ms810603.aspx
Fa is a musical note to play with CL

Tedd

GetProcessHeap returns the heap (that has already been allocated) for the process -- it doesn't cause a new one to be allocated.
Since you didn't allocate it (or cause it to be allocated on your behalf), you don't need to free it (and can't.)
Potato2