memory allocation

Started by
4 comments, last by DarkEmpire 21 years, 10 months ago
Hi, What is the differences between : GlobalAlloc / LocalAlloc / HeapAlloc ? What is better ? what is faster ? Which should i use ? Thanks
Advertisement
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...
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
I know malloc() and free() don''t call ctors/dtor like new and delete do but what about HeapAlloc?
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
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.

This topic is closed to new replies.

Advertisement