• Advertisement
Sign in to follow this  

Memory allocation

This topic is 4839 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

For a medium complexity game, is best to use new/delete (or malloc/free) function every time you need alloc or release memory, or is best to allocate much memory at start, and use a class to manage this allocated memory ? thnx

Share this post


Link to post
Share on other sites
Advertisement
In most cases it'll be better to allocate memory at the start rather than on-demand because memory allocations are generally slow. You'll probably want to allocate a decent amount of memory at the start of your program to avoid having to allocate memory in time-critical sections of your code.

Share this post


Link to post
Share on other sites
Of course, new/delete can be overloaded (globally or on a per-class basis) to use a more specialized memory allocation routine, including one that pre-allocates the memory up-front. That way you don't have to change how you program if you determine that you need to do memory pooling later on.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement