   Assigning and storing on multidimensional vectors c++
Hello everybody!Just two small questions.1) If I create the following two matrices:vector<vector<int> > mat_1, mat_2;// Code to initialize both matrices.// Code to store something on mat_2.Is it correct to do the following assignment?// Later on the code. mat_1.assign(mat_2.begin(), mat_2.end());I tested it and apparently it works fine... but I don't know if it's safe with multidimensional vectors as when using it with one dimensional vectors.2) I'm also using the following multidimensional vectors:vector<vector<vector<GLfloat> > > mat_vert, mat_norm;to store vertices and normals. Is this a good idea? Is it much better to use the multidimensional arrays on the boost library?Thank you very much in advance!
  1) You can just do mat1 = mat2.2) Using vectors of vectors is generally a pretty bad idea - it really louses up the cache. I would recommend using boost::multi_array over vectors of vectors.   ;Quote:Original post by SiCrane1) You can just do mat1 = mat2.2) Using vectors of vectors is generally a pretty bad idea - it really louses up the cache. I would recommend using boost::multi_array over vectors of vectors.Dear SiCrane,Thanks for your quick reply!Maybe I should have been more specific in the way I intended to use the assignment.The idea is to have a bigger 2-dimensional vector to store the control points of a Bezier curve, and then assign a contiguous part of it to another smaller 2-d vector.Something like this:mat_1.assign(mat_2.begin() + index, mat_2.begin()+ index + stride);Is it ok?I'll take a look at the boost lib!Thanks again! [smile];  Yes, that use of assign() looks right - provided, of course, that all the indices are in range.   ;Quote:Original post by SiCrane2) Using vectors of vectors is generally a pretty bad idea - it really louses up the cache. I would recommend using boost::multi_array over vectors of vectors.The nested vector approach also wastes space and is unclear about intent. boost::multi_array is always rectangular. A vector of vectors must be maintained that way.But most of the time that you are working with matrices, you know the size ahead of time anyway. So it makes even more sense to use nested boost::arrays or something similar. :)   ;Quote:Original post by ZahlmanQuote:Original post by SiCrane2) Using vectors of vectors is generally a pretty bad idea - it really louses up the cache. I would recommend using boost::multi_array over vectors of vectors.The nested vector approach also wastes space and is unclear about intent. boost::multi_array is always rectangular. A vector of vectors must be maintained that way.But most of the time that you are working with matrices, you know the size ahead of time anyway. So it makes even more sense to use nested boost::arrays or something similar. :)Dear Zahlman,Now that you say that I know the size ahead of time, I realize that maybe the correct words that I should have used are "multidimensional arrays" (instead of matrices). I use them to store hundreds of vertices and normals of a surface, and the final size is defined by the user during runtime, so I need their size to be dynamic.It seems that boost is the way to go :)Thanks for your advice!PS: I apologize for the misunderstanding.;  Aha. Well, the important thing is that you know what you need :) But it is also important to know what tools are available, so you can pick the best one (or combination) for the job.   