# simple question about OpenFoam matrix class

 Register Blogs Members List Search Today's Posts Mark Forums Read

 August 8, 2018, 09:37 simple question about OpenFoam matrix class #1 Senior Member   Join Date: Oct 2017 Location: United States Posts: 228 Blog Entries: 1 Rep Power: 7 Hello, I have one simple question about OpenFoam matrix class. In it's definition, the function 'allocate' says: Code: ```void Foam::Matrix::allocate() { if (n_ && m_) { v_ = new Type*[n_]; v_[0] = new Type[n_*m_]; for (register label i=1; i

 August 9, 2018, 02:47 #2 Senior Member   Gerhard Holzinger Join Date: Feb 2012 Location: Austria Posts: 316 Rep Power: 26 My guess is that two memory allocations Code: ```v_ = new Type*[n_]; v_[0] = new Type[n_*m_];``` were deemed more efficient than doing n+1 allocations Code: ```v_ = new Type * [n_]; for(i=0; i::allocate() { if (n_ && m_) { v_ = new Type*[n_]; v_[0] = new Type[n_*m_]; for (register label i=1; i

August 10, 2018, 20:53
#3
Senior Member

Join Date: Oct 2017
Location: United States
Posts: 228
Blog Entries: 1
Rep Power: 7
Quote:
 Originally Posted by GerhardHolzinger My guess is that two memory allocations Code: ```v_ = new Type*[n_]; v_[0] = new Type[n_*m_];``` were deemed more efficient than doing n+1 allocations Code: ```v_ = new Type * [n_]; for(i=0; i::allocate() { if (n_ && m_) { v_ = new Type*[n_]; v_[0] = new Type[n_*m_]; for (register label i=1; i

I still don't get it. With this one
Code:
`v_[0] = new Type[n_*m_];`
doesn't it mean all the elements will be saved in v[0][i] ? If so, why doesn't it just declare a 1D array to save the entire matrix?

 Tags matrix, openfoam