Jump to content
  • Advertisement
Sign in to follow this  
mattnenterprise

dynamic memory allocation

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

Advertisement
As far as i know, it wont cause slow down to ur program. In fact, when i am doing model animation, its faster to use dynamic memory.

Share this post


Link to post
Share on other sites
Working with dynamically allocated memory is not slower than working with any other memory. However, allocating and deallocating memory may have a performance impact, depending on the heap implementation.

It is generally a good idea to avoid very frequent allocations, as it will hurt performance and fragment the memory. This is a big concern in console development.

Share this post


Link to post
Share on other sites
As stated above, dynamic memory allocation and deallocation in languages without a garbage collector tends to be slow, so it should be avoided in high-performance situations.

Share this post


Link to post
Share on other sites
Quote:
Original post by mattnenterprise
I program in C++ and I was wondering if using dynamic memory allocation could cause a program to run slower even if it is used correctly.


No, the only thing that causes the program to run slower is lowering the CPU frequency.

A CPU needs a given number of cycles to perform a certain task. As such, slower or faster is problematic metric. One can talk about "cost" (how many cycles are needed to perform a certain task).

Slow can be applied in terms of FPS, but that isn't accurate metric, since in multi-threaded renderer, your FPS can remain the same, but actual rate of simulation starts dropping and can't keep up with renderer.


A "correctly" used and implemented algorithm will not cause a slowdown. It will use exactly the needed number of cycles, including dynamic allocations. These can be performed on stack, on heap, in pre-allocated buffers, in virtual memory, on a remote system, in graphics memory, ....

So when talking about "correctly implemented", the answer is simply - your algorithm may be too expensive for the given hardware.

Naive use of new/malloc however can cause algorithm to allocate memory in sub-optimal manner, causing your algorithm to be more costly than it could (or even should) be.

Share this post


Link to post
Share on other sites
Memory fragmentation can make performance noticeably worse, so like Rattenhirn said, it's good to avoid frequent allocations. Searching through a fragmented heap will have overhead. One way to minimize this is to use memory pools.

Share this post


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

  • 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!