Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

LocalAlloc vs malloc?

516 views
Skip to first unread message

Greger Haga

unread,
Aug 30, 2002, 6:47:46 AM8/30/02
to
what's the difference?
G


Slava M. Usov

unread,
Aug 30, 2002, 11:44:51 AM8/30/02
to
"Greger Haga" <grege...@pp.inet.fi> wrote in message
news:m3Ib9.161$kq4....@read2.inet.fi...
> what's the difference?

One is provided by win32, another by the Standard C libraries. One is
portable across multiple platforms, another is not. Both of them allocate a
specified amount of memory, both return zero when they fail. LocalAlloc() is
mostly for compatibility with 16 bit Windows. Modern C/C++ programs should
use malloc() or the operator new to allocate memory.

S


Tom Stewart

unread,
Aug 30, 2002, 1:05:56 PM8/30/02
to
HeapAlloc is the preferred "pure Win32" alternative to LocalAlloc.

"Slava M. Usov" <stripit...@gmx.net> wrote in message
news:uN2TLwDUCHA.1668@tkmsftngp13...

Jeff Henkels

unread,
Aug 30, 2002, 4:39:07 PM8/30/02
to
To confirm Tom's statement, if you look at the MSVC CRT source code (at
least for MSVC 6.0), you'll see that both malloc and new end up calling
HeapAlloc.

"Tom Stewart" <tast...@msdn.microsoft.com> wrote in message
news:#n$EgdEUCHA.1864@tkmsftngp12...

Jon Wiswall [MS]

unread,
Sep 1, 2002, 1:16:57 PM9/1/02
to
However, don't take this as free reign to do the following:

PVOID pvFoo = malloc(10);
LocalFree(pvFoo);

Conceptually, they're different allocators, and the acquire/free APIs used
must match.

--
Jon Wiswall - Microsoft
This posting is provided AS IS with no warranties, and confers no rights.


"Jeff Henkels" <je...@mapson.privatemail.com> wrote in message
news:#Q2znUGUCHA.2320@tkmsftngp12...

0 new messages