c++ pointer to pointer to pointer to pointer
Hello. Have any of you found any practical use of **** - pointer to pointer to pointer to pointer? If you did probably to confuse anyone reading your code. Or else?
A linked list is a 'Node **********...*node'.
Such syntax makes me want to do painful things to the author of the code.
Quote:If you did probably to confuse anyone reading your code.
Such syntax makes me want to do painful things to the author of the code.
A four-dimensional lattice to simulate quantum chromodynamics -- http://en.wikipedia.org/wiki/Lattice_QCD
However, vector<vector<vector<vector<type>>>> lattice; might be a better choice, in order to avoid potential memory leaks.
Either way, the usage syntax is not confusing beyond the allocation stage. One can use array notation for either pointer or vector cases, ex: lattice[t][x][y][z].whatever = 0;
**** Edit: See sneftel's response below (and my response to that) for a better solution.
[Edited by - taby on June 11, 2008 12:18:07 PM]
However, vector<vector<vector<vector<type>>>> lattice; might be a better choice, in order to avoid potential memory leaks.
Either way, the usage syntax is not confusing beyond the allocation stage. One can use array notation for either pointer or vector cases, ex: lattice[t][x][y][z].whatever = 0;
**** Edit: See sneftel's response below (and my response to that) for a better solution.
[Edited by - taby on June 11, 2008 12:18:07 PM]
Quote:Original post by taby
A four dimensional lattice to simulate quantum chromodynamics -- http://en.wikipedia.org/wiki/Lattice_QCD
However, vector<vector<vector<vector<type>>>> lattice; might be a better choice.
vector<type>, with appropriate subscripting, would be an even better choice. Simulating multidimensional grids with nested one-dimensional containers is inefficient and wasteful.
Quote:Original post by SneftelQuote:Original post by taby
A four dimensional lattice to simulate quantum chromodynamics -- http://en.wikipedia.org/wiki/Lattice_QCD
However, vector<vector<vector<vector<type>>>> lattice; might be a better choice.
vector<type>, with appropriate subscripting, would be an even better choice. Simulating multidimensional grids with nested one-dimensional containers is inefficient and wasteful.
Ah yes, good point.
In that case, it would work out to something like:
vector<type> lattice;
lattice.resize(t_size*x_size*y_size*z_size);
size_t index = t*x_size*y_size*z_size + x*y_size*z_size + y*z_size + z;
lattice[index].whatever = 0;
It's been a while since I've done anything like this.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement