My problem is here.
I have four 3-dimensional tables which are a sort of look up tables ( 32x32x32 ) where I have to retrieve values in real time and very quickly in c++.
My main goal is computational time as a very large amount of operations have to be made, and good programming practice is secondary for this, as I’m less worried about code maintaining.
What is the best solution on the majority of personal computer to achieve this?
I’ve thought of storing the data on global variables and put them in a separate file and using them through declarations like “extern const float first[32][32][32];” or loading a vector from a file.
But the latter, I suppose, would be slower because data have to accessed through one more pointer.
Any other solution?
I made a search on the web, but this confused me more as I read different truths.
For example this two websites don’t seem to suggest the same thing (if I understand correctly): site1 , site2
Accessing data in a multidimensional array
is exactly equivalent to accessing a flattened array
There is no extra pointer involved, just arithmetic on the array indexes.
In terms of performance, an
extern const float [32][32][32]will offer the compiler opportunities for whole program optimisation as it will have full access to the data and how you are using it.Loading data from a file into a dynamic-sized
vector<vector<vector<float>>>would result in multiple pointer indirections to access data elements; given that you know the size of the data, loading it into astatic float[32][32][32]would be more efficient.For data where the extents are unknown at compile time, a good option would be to use Boost.MultiArray: