If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

static vs dynamic array

Hi,
I was just curious if there is a performance difference (e.g access time, speed, ...) between allocating static memory vs dynamic memory?
For example, if am reading data from a file, and storing them inside a huge buffer, what would be the differences between storing these data inside a static buffer vs a dynamic one?

Re: static vs dynamic array

The only speed difference should in the allocation/deallocation; access times should be equivalent. For a static array allocation/deallocation is nearly instant, for a dynamic array (I hope you use std::vector instead) a call to new[]/delete[] is required, the performance of which is not always the same, but always slower than for a static array. The unpredictability of performance for dynamic arrays can also be a reason to prefer static arrays in real-time systems.

Cheers, D Drmmr

Please put [code][/code] tags around your code to preserve indentation and make it more readable.

As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

Re: static vs dynamic array

Re: static vs dynamic array

not quite.
ALl dynamic arrays work off a pointer pointing to some allocated bit of memory.
This is an extra level of indirection that isn't there when using a fixed array. This will also have a small effect on performance.

* The Perfect Platform for Game Developers: Android
Developing rich, high performance Android games from the ground up is a daunting task. Intel has provided Android developers with a number of tools that can be leveraged by Android game developers.

* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.