Page 1 of 1

GlobalAlloc_() verses AllocateMemory()?

Posted: Thu Jul 03, 2003 9:41 pm
by Karbon
In Windows, is there a difference between the winAPI GlobalAlloc_() and the PB proc AllocateMemory()?

I see lots of people using GlobalAlloc_() in their examples but don't see any obvious differences..

Thanks!

[edit]

Ok, so I do see one difference.. Flags aren't supported by AllocateMemory() like : GlobalAlloc_(#GMEM_FIXED | #GMEM_ZEROINIT, #BUFFERSIZE)

... but is that the only difference?

Re: GlobalAlloc_() verses AllocateMemory()?

Posted: Thu Jul 03, 2003 10:02 pm
by GPI
The diffrent is, that you must give AllocateMemory() a nr and globalAlloc gives you a "nr" (ok, it is a adress, but it is also the "handle" for the memory)

When you programm a routine, that is in the window-callback, timer and so on, you can get problems, that a routine can called twice and so you get a already allocate error.

Re: GlobalAlloc_() verses AllocateMemory()?

Posted: Thu Jul 03, 2003 10:29 pm
by Karbon
GPI wrote:When you programm a routine, that is in the window-callback, timer and so on, you can get problems, that a routine can called twice and so you get a already allocate error.
Problems when using GlobalAlloc_() or PB's AllocateMemory()?

Thanks for the info!

Re: GlobalAlloc_() verses AllocateMemory()?

Posted: Thu Jul 03, 2003 11:44 pm
by tinman
Karbon wrote:
GPI wrote:When you programm a routine, that is in the window-callback, timer and so on, you can get problems, that a routine can called twice and so you get a already allocate error.
Problems when using GlobalAlloc_() or PB's AllocateMemory()?
PB's AllocateMemory() because you must specify a bank number. It's a pain when you are working with (lots of) dynamic memory allocations because not only do you need to keep track of the pointer to the memory (or course, you'd need to do this with GlobalAlloc_() anyway) but you must also keep track of what memory banks you have used.

Posted: Thu Jul 03, 2003 11:48 pm
by Karbon
Got ya. Thanks!!!

Posted: Fri Jul 04, 2003 12:09 am
by freak
GlobalAlloc_() is an old, outdated function, which is only still there for
backward compatibility and for some stuff like clipboard management.

You should use the Heap functions like HeapAlloc_() and so on, because
they are faster than GlobalAlloc_(). PB's AllocateMemory() uses the Heap
stuff if i'm not wrong, so it should be a bit faster than GlobalAlloc_().

Timo