Subj : Re: Matrix Operation To : borland.public.cpp.borlandcpp From : maeder Date : Sat Apr 23 2005 12:30 am "Mohsen" writes: >>Whether it is possible depends on how the matrix elements are stored. > > How can I store a two dimension matrix efficiently? Is there a > better alternate for the following? > > double** data; > > data = new double* [rows]; > > for (unsigned i = 0; i < rows; i++) > data[i] = new double[columns]; There are many ways to store a matrix, and you didn't tell us which one you are using, so I asked. What is better depends on your requirements. Among those I usually want to meet are simplicity of the code and robustness. Therefore, I'd wrap these arrays up in smart pointers or container objects. One obvious alternative is an array with rows*columns elements. This will certainly speed up both allocation and deallocation. I'm not an expert, but the contiguity of all the elements also might have an impact on how the matrix can be cached. .