LPTSTR ReferencedDomain=NULL;
to clear the memory block, do these two functions do the same thing? Are
they interchangeable?
HeapFree(GetProcessHeap(), 0, ReferencedDomain);
LocalFree(ReferencedDomain);
msdn says to use the heap functions because they are faster but besides
that, are there any other advantages?
No. HeapFree deallocates memory allocated with HeapAlloc. LocalFree
deallocates memory allocated with LocalAlloc.
LocalAlloc et al are retained for backward compatibility and should not
be used in new code.
Note also that your example won't compile. LocalFree takes HLOCAL handle
as a parameter, rather than a pointer.
Why do you have to go through Win32 API for your memory management? You
may find that 'new' (in C++) or malloc (in C) are more convenient.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
Use HeapFree to free memory allocated with HeapAlloc or HeapReAlloc. Use
LocalFree to free memory allocated with LocalAlloc. So no, they are not
interchangeable.
Heinz
However, the LocalFree documentation says to use the Heap functions and I've
seen people use things like HeapFree(GetProcessHeap(), 0, ReferencedDomain);
So now the questions I ask myself are what is the most appropriate way to
clear the assigned memory block? and if I am NOT using LocalAlloc or
HeapAlloc, which one do I use and is there a difference between the two?
p.s. the example given in the previous post compiles and runs without error
"Igor Tandetnik" <itand...@mvps.org> wrote in message
news:uutHdkTo...@TK2MSFTNGP03.phx.gbl...
First, Igor's reply is spot on. Allocator and deallocator functions always
come in pairs. You can't mix and match them.
Second, LocalAlloc() goes way back. It's use is generally deprecated.
Third, operating system vendors often find themselves stuck between a rock
and a hard place. They can deprecate the use of a function, but if they
retire support for it then old code will break.
Fourth, and this is the crux of the issue, SetEntriesInAcl() returns a
pointer to a buffer that was allocated by means of LocalAlloc(). The docs
say you must use LocalFree() to free it. The operating system is always
right. :-)
It has done this forever. It likely won't change anytime soon. The fact that
it still uses the old disfavored allocator is one of those "grin and bear
it" facts of life. In fairness, any performance penalty should be
negligible.
Regards,
Will
OK makes more sense now that someone pointed out (the obvious fact) that
SetEntriesInAcl used LocalAlloc
Thx everyone for clearing this up.
Ryan