What overhead are you talking about with std::vector? |
My main beef with using the vector for this particular application is that it requires more storage and would involve another degree of indirection which would significantly slow down the problem.
1 2
|
double F[3][3];
F[0][2]; // <-- one address calculation
|
versus
1 2
|
std::vector<std::vector<double>> F;
F[0][2]; // <-- two address calculations (F[0], then ->[2])
|
In addition, the 2d array vector form may not be allocated contiguously in storage. By this I mean F[0][2] is almost certainly not next to F[1][0]. Right? I'm not exactly sure how vector is doing its memory allocations.
In addition, the vector form requires more memory. For this size array, it requires nearly twice as much memory at a minimum (8 ints + 9 doubles). Now, I realize that in the vast majority of applications, both of these issues are negligible as most applications are not computational in nature. My application is computational in nature. The number of
double F[3][3] objects in storage is essentially unlimited (i.e. hundreds of thousands, pushing memory limits). Even increasing the size by adding a few extra int's (vector size and capacity) will have an effect, and the increased cost of two indirections while doing computations will also have an effect. Again, I know in most applications this isn't an issue. However, I routinely run my code for days at a time, so even a 20% increase in speed is a big deal for me.
The other problem with vector is that initialization is not as simple/clear as
|
double F[3][3] = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
|
The second Array2D example by Disch keeps looking better as I reread this thread as one could add in debug checks for bounds, but the accessibility and storage are identical as the standard 2D array case. I would imagine this is equivalent to the boost implementation.
I haven't looked at boost too much, but I don't want to install an external library, even one so well developed and maintained as boost. Again, personal preference.
I hope that some of those ideas are received as constructive. |
Yes, they are, thank you. Programming is always a learning experience, no matter what level you're at.