GlobalAlloc_() verses AllocateMemory()?

Everything else that doesn't fall into one of the other PB categories.
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

GlobalAlloc_() verses AllocateMemory()?

Post 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?
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Re: GlobalAlloc_() verses AllocateMemory()?

Post 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.
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Re: GlobalAlloc_() verses AllocateMemory()?

Post 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!
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Re: GlobalAlloc_() verses AllocateMemory()?

Post 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.
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

Got ya. Thanks!!!
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
freak
PureBasic Team
PureBasic Team
Posts: 5946
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post 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
quidquid Latine dictum sit altum videtur
Post Reply