B
BobR
(e-mail address removed) wrote in message ...
What do you have against std::vector? I use a vector of 3D points(double
x,y,z) to store a '3D rock' which animates smoothly, 30k+ triangle-mesh in
OpenGL running in wxWidgets.
Vector is contiguous.
#include <iostream> // 2D example
#include <vector>
// ........
size_t Rows( 480 );
size_t Columns( 640 );
std::vector<std::vector<double> > My2Darray( Rows, Columns );
std::cout<<"My2Darray.size() ="<<My2Darray.size()<<std::endl;
std::cout<<"My2Darray.at(0).size() ="<<My2Darray.at(0).size()<<std::endl;
std::cout<<"row 7 col 9 ="<<My2Darray.at(7).at(9)<<std::endl;
Now you don't need to worry about 'new/delete[]'.
[ Sorry if this was all 'old hat' to you. Maybe it will help some newbie. ]
I, indeed, am working in a image processing application and was trying
to figure out if a 2D array is better for dynamic allocation or a big
1-dimensional one.
Case 1: 1D case will allocate it in one go. So contguity is there
indeed.
Case 2: 2D will involve memory to be new'd (again, grammatical usage is
casual here. This is *NOT* correct english.) once for the columns and
then itertively with in a 'for' loop so as to cover the rows.
int** array2D = new int*[height];
for (int i=0; i<height; i++){
array2D = new int[width];
}
My querry is that whether this array2D is contiguous or not.
So far so good.. now which of these 2 cases will be faster to access?
Obviously the one which is contiguous. Hence this question on the
newsgroup.
What do you have against std::vector? I use a vector of 3D points(double
x,y,z) to store a '3D rock' which animates smoothly, 30k+ triangle-mesh in
OpenGL running in wxWidgets.
Vector is contiguous.
#include <iostream> // 2D example
#include <vector>
// ........
size_t Rows( 480 );
size_t Columns( 640 );
std::vector<std::vector<double> > My2Darray( Rows, Columns );
std::cout<<"My2Darray.size() ="<<My2Darray.size()<<std::endl;
std::cout<<"My2Darray.at(0).size() ="<<My2Darray.at(0).size()<<std::endl;
std::cout<<"row 7 col 9 ="<<My2Darray.at(7).at(9)<<std::endl;
Now you don't need to worry about 'new/delete[]'.
[ Sorry if this was all 'old hat' to you. Maybe it will help some newbie. ]