beren.olvar
February 16th, 2009, 04:34 PM
Hi there,
I am trying to do a program that need dynamical allocation of memory in C++.
In particular I need to have a 3D array which can change its size, so I do
double ***some;
some=new double**[Nx];
for(int i=0; i<Nx;i++){
some[i]=new double*[Ny];
for(int j=0; j<Ny;j++){
some[i][j]=new double[Nz];
}
}
where, of course Nx,Ny and Nz, are previously determined.
After that I need to pass that matrix to some function
void function(double ***some){
...
some[i][j][k]=something;
...
}
to get back the results.
The problem is that it works for little matrices, but for larger N? i start getting problems and SIGSEGV. Probably becouse of the memory is not being allocated in a continuos way, so doing "some[i][j][k]" in "function" gives back a wrong place in memory.
Can that be the problem? If so, how can I solve it?
hope there is an easy way!!
thanks!
I am trying to do a program that need dynamical allocation of memory in C++.
In particular I need to have a 3D array which can change its size, so I do
double ***some;
some=new double**[Nx];
for(int i=0; i<Nx;i++){
some[i]=new double*[Ny];
for(int j=0; j<Ny;j++){
some[i][j]=new double[Nz];
}
}
where, of course Nx,Ny and Nz, are previously determined.
After that I need to pass that matrix to some function
void function(double ***some){
...
some[i][j][k]=something;
...
}
to get back the results.
The problem is that it works for little matrices, but for larger N? i start getting problems and SIGSEGV. Probably becouse of the memory is not being allocated in a continuos way, so doing "some[i][j][k]" in "function" gives back a wrong place in memory.
Can that be the problem? If so, how can I solve it?
hope there is an easy way!!
thanks!