Skip to main content
gamedev.net
🔒 Locked

memory allocation

Started by DarkEmpire Jun 2, 2002 at 1:30 PM 4 replies 250+ views
Original Post
DarkEmpire
DarkEmpire
Hi, What is the differences between : GlobalAlloc / LocalAlloc / HeapAlloc ? What is better ? what is faster ? Which should i use ? Thanks
-Thork-
-Thork-
GlobalAlloc and LocalAlloc are only included for compatability with 16-bit versions of Windows. If you''re building a Win32 app, you should use HeapAlloc, despite how much of a pain it can be at times.

As far as I know, there is no particular difference in speed, but that said, I''ve never timed it...
Jason2Jason
Jason2Jason
out of the blue: I use malloc() and free(). I''m not sure if its the right thing todo, but it works for me.

-J
-Moxie-
-Moxie-
I know malloc() and free() don''t call ctors/dtor like new and delete do but what about HeapAlloc?
Fruny
Fruny
Nope, all it does is allocate memory, not create objects.

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Dean Harding
Dean Harding
If you look at the source for malloc it calls HeapAlloc internally (well, on windows it does, there''s probably some other system call on other platforms).

The basic point is that malloc, free, new and delete are portable, while HeapAlloc & co. are not.


codeka.com - Just click it.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.