Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

comparing memory allocation methods

Status
Not open for further replies.

wduty

Programmer
Jun 24, 2000
271
US
I am writing a program which will require allocating and deallocating a potentially large number of buffers. Is there any advantage to using malloc vs new vs GlobalAlloc vs LocalAlloc etc. ? I have used all of these methods to the same effect and never noticed any performance difference. Any advice?

--Will Duty
wduty@radicalfringe.com

 
I would definitely use malloc over some Win32 memory allocation functions. The C libraries are always going to be faster than Microsoft libraries. The new operator is going to be slower than malloc but not by much. The new operator calls malloc (among other things) so you loss the speed of a function call - not that big of a deal. I would say malloc is better for larger chucks since its made for that. Remember C is good, C++ is ok, and MFC is bad -alright MFC isn't bad it is helpful for a lot of stuff and I'm sure as heck glad it's around. I'm just saying give me main() over winmain() any day!

bitwise
 
in Win32 GlobalAlloc and LocallAlloc exists only for compatibility with Win16. The new functions are such HeapAlloc,... All the allocation in Win32 is local. John Fill
1c.bmp


ivfmd@mail.md
 
Thanks guys. The plan was pretty much to use malloc anyways but I just wanted to see some feedback.

As to your comment:

>>MFC is bad -alright MFC isn't bad it is helpful for a lot of stuff and I'm sure as heck glad it's around. I'm just saying give me main() over winmain() any day!

I would agree that MFC is bad. A bunch of wrappers for what are already pretty easy to use (though not particularly elegant) system calls doesn't make sense to me except to try to appease OO purists. But WinMain's there whether you're doing MFC or Win32 (though you don't see it in MFC).
--Will Duty
wduty@radicalfringe.com

 
WDutty, I really apreciate your opinion about MFC, but to say "MFC is bad" is some thing like say "I'm amateur". Is better you to say "I don't know MFC", and you will noy look like a dilettante. John Fill
1c.bmp


ivfmd@mail.md
 
You must be quite an MFC champ and not a "dilettante" like me. You should try Visual Basic - it's even easier...
--Will Duty
wduty@radicalfringe.com

 
wduty
True, VB is easier that C++, but there are several things that you can't do it VB that you need to do in C++. - Jeff Marler B-)
 
I was just kidding because I found Mr. Fill's remarks insulting. He evidently found my comments about MFC insulting as well.
In all honesty, MFC's fine: lots of people use it, it works, it does make a lot of things easier, etc. and I have used it, (though as an amateur I'm told).
I just have never found anything that I couldn't do with plain old win32 so MFC seems like an unnecessary layer. Just my OPINION.
--Will Duty
wduty@radicalfringe.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top