Hello everybody.

Just a query (in fact two)

I have a reasonably huge matrix type data which is to be used via some other calculations, In the matrix are values of 1s, 0s and -1s which will appear in random and the actual i-jth position is important.

Is it any good to have a vector of pointers and will this be faster than some 'matrix' form?

the second query is about the best way (faster) you'd think to have matrix data stored. I've used

vector<vector<double>>

normally, This can be around C or C++ although i am using C++ at the moment.

Just a few sentences and a direction will suffice, examples are a bonus to me :)

Thank you in advance coders

Use the simplest method until you can prove that it doesn't perform well enough for your needs. A vector of vectors will probably be the simplest, and should also be sufficiently fast, but there's no way of knowing until you've profiled it with a realistic data set.

Use the simplest method until you can prove that it doesn't perform well enough for your needs. A vector of vectors will probably be the simplest, and should also be sufficiently fast, but there's no way of knowing until you've profiled it with a realistic data set.

Although I would like to point out that choosing the correct data structure at the beginning would serve you best, because if you choose the wrong data structure for your problem only to find out at the end after all the performance increase, the data structure wasn't fast enough and now your left with rebuilding it all. But right now a vector of vector of ints would suffice for {-1,0,1} ranged values, or even vector of vector of chars.

What I would suggest for you to do is, use a matrix class that someone already wrote and tested and benched marked, so you don't have to worry about it. Else if you want to create your own, wrap it in some interface, so the public interface won't change, but your lying implementation might, for example you might choose to represent a matrix by a regular 1D array.

This article has been dead for over six months. Start a new discussion instead.