Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

n0ob

malloc vs globalalloc vs new

This topic is 5657 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

char * buf; buf = (char*)GlobalAlloc(GPTR, len + 1); buf = (char*)malloc(len+1); buf = new char[len+1]; Is there any difference that would make one faster, or safer? I want speed. Kings of Chaos

Share this post


Link to post
Share on other sites
Advertisement
Optimizing on this level is not wise in general, but outside of that point use ''new'' and ''delete''. When/If you want to optimize your memory usage (ie- providing contiguous blocks of a pre-allocated heap, etc) then you can overwrite the new and delete operators.

Share this post


Link to post
Share on other sites
If you really want speed, then you should make a MemoryManager class which allocates a variable size of memory at the beginning of the program. Then you should override the new operator to ask this memory manager for memory, which just returns a pointer to a place in it's array.

All the memory manager should do, is check if it has any memory left, check which memory is unused and make sure that there is a big enough block for the wanted size of memory. Also when you free any memory from this memory manager, it should just mark the used memory as unused.

[edited by - angry on June 19, 2003 7:51:44 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by angry
If you really want speed, then you should make a MemoryManager class which allocates a variable size of memory at the beginning of the program.



boost:: pool.


[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]

Share this post


Link to post
Share on other sites
quote:

boost:: pool.



I don''t use other libs if I don''t really have to, they screw up my coding style

Share this post


Link to post
Share on other sites
quote:
Original post by angry
I don''t use other libs if I don''t really have to, they screw up my coding style


Don''t you use libraries to make things easier and to allow you to be productive and get on with the task at hand, instead of endlessly reinventing buggy wheels?

Unless you''re just doing it for the learning experience or because the libraries don''t meet your very specific and uncompromisable needs, it''s a real waste of time.

Share this post


Link to post
Share on other sites
quote:

I don''t use other libs if I don''t really have to, they screw up my coding style



heh, question is, does that make u a better or worse programmer?

Share this post


Link to post
Share on other sites
quote:

Don''t you use libraries to make things easier and to allow you to be productive and get on with the task at hand, instead of endlessly reinventing buggy wheels?


I don''t write buggy wheels. Endlessly reinventing the wheel? eh you only have to reinvent one wheel one time.

quote:

Unless you''re just doing it for the learning experience or because the libraries don''t meet your very specific and uncompromisable needs, it''s a real waste of time.


Waste of time? I would call it a time of fun experience. However if you been programming for 4 years, then you don''t have to reinvent much as you''ve done it along the way.

quote:

Well, you''re using the Win32 library so your coding style is probably already screwed. (just kidding)


Yes it did, until I made my win32 wrapper which hides all the ugly code

quote:

heh, question is, does that make u a better or worse programmer?


I would think a better programmer, because think of all experience ive got when reinventing the wheel, when others in here has gone out on the web and searched like crazy for code just so that they don''t have to reinvent the wheel and perhaps gain some experience along the way.
I think everyone should write their own string class, memory allocator, linked list, array class, multi type class etc... I mean it''s not taking forever.. And once you''ve done that you dont need to do it again.

Also I''ve noticed when somebody in here asks about char strings, people tend to jump at them telling them to use std::string instead, i mean eh... thats just avoiding the problem, he should at least learn char strings.. thats like the basics of c/c++.. So I think people are to afraid of coding something thats already been done, which is a bad thing.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!