-
February 27th, 2013, 12:46 PM
#1
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?
Thanks,
--Rudy
-
February 27th, 2013, 01:25 PM
#2
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
-
February 27th, 2013, 03:26 PM
#3
Re: static vs dynamic array
Okay Thanks. It makes sense
-
March 1st, 2013, 09:02 AM
#4
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.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|