so, can annyone tell me the difference and what to use?
thanktankkk
/btq
(was this a dumb question?)
so, can annyone tell me the difference and what to use?
thanktankkk
/btq
(was this a dumb question?)
use new.
new calls class constructors and delete calls destructors.
Best Regards,
Bonkey
he may not be coding C++.
That having been said, I see no advantage to HeapAlloc over new. GlobalAlloc at one time had an advantage but may not anymore. However, GlobalAlloc is still necessary for certain operations such as Clipboard copying and pasting of odd types.
These allocation routines have the feature of using handles, thus "movable" memory. However I think I remember hearing that all memory was "virtual pointer" anyway in 32 bit. This includes new. That last bit I'm not entirely sure of but if true completely negates the reasons for using GlobalAlloc and HeapAlloc
"You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter
HeapAlloc is an API...its a function that's part of the system's documented interface
new is an operator that's implemented in the C++ libraries..as said, it calls constructors and is more type safe.....on many implementations (including VC++) it calls malloc (its C counterpart) to do the dirty work (malloc could then call HeapAlloc to do the dirty work - not too sure on this, but I have noticed calls to something resembling HeapAlloc in the bowels of malloc )
GlobalAlloc is remnant of 16bit windows... these days it probably calls HeapAlloc and is slower than needs be......you cant use it to transfer memory between processes anymore, so its largely just for legacy code...Also, the return is a handle but that is just a 32bit pointer anyway and all GlobalLock seems to do is cast to LPVOID....so IMO, forget GlobalAlloc....
My preference - I try to use "new" as much as possible
thanks for yer replies...although I was more interested in how they relate when it comes to allocating memory on the heap in terms of heapfragmentation, speed issues etc...
but thanks anyhow
/btq
Here's an essay (well more of a rambling) by someone who knows his stuff here