I have a really very basic doubt regarding STL containers.
My requirement is that i want to store double values in the form of multi-dimensional array. I will be performing various algebraic operations directly on them i.e.
myvector[4] = myvector[3] - 2 * myvector[2];
for this I am itterating using for loops & using the [] operator. I am not using STL itterator’s. I found 2 basic approaches here.
I prefer speed over memory efficiency. Since I am accessing these variables frequently I think vector would be slow for me.
So what is your humble opinion on this matter?
I know that the answers would be based on your previous experience, that is why I am asking this question. I am sorry if this question is too basic to be discussed here.
The link you gave listed 2 methods, which creates “real” 2d arrays. In general, 2d arrays are not that efficient, because they require a lot of allocations. Instead, you can use a faked 2d array:
Here is a simple benchmark (windows only, except if you change the timer part):
Compiled with msvc2010, release /Ox /Ot, it outputs for me (Win7 x64, Intel Core i7 2600K):
You can see the STL is equivalent to raw pointers. But 1D is much faster than 2D.