By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,125 Members | 1,249 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,125 IT Pros & Developers. It's quick & easy.

maybe a problem with pointers

P: n/a
The following 'minimal example' code works(to my knowledge) but it
envokes some strange behaviour of my computer, not fatal, but some
strange lag.
i have a feeling i did something wrong with a pointer or two.
Did i make an error in this code ?? or is it my imagination.

int ***neuralNetwork;
int width;
int hight;
int depth;

// making
neuralNetwork = new int **[width];
for (int i=0; i < width; i++)
{
neuralNetwork[i] = new int *[hight];
for (int j=0; j < hight; j++)
neuralNetwork[i][j] = new int[depth];
}
// filling
for (int i = 0; i < depth; i++)
for (int k = 0; k < hight; k++)
for (int j = 0; j < width; j++)
neuralNetwork[j][k][i] = 0;
// deleting
for (int i=0; i < width; i++)
{
for (int j=0; j < hight; j++)
delete [] neuralNetwork[i][j];
delete [] neuralNetwork[i];
}
delete [] neuralNetwork;

Aug 5 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
mrDumbass wrote:
The following 'minimal example' code works(to my knowledge) but it
envokes some strange behaviour of my computer, not fatal, but some
strange lag.
i have a feeling i did something wrong with a pointer or two.
Did i make an error in this code ?? or is it my imagination.
The code as is cannot be compiled, nor can it be used even after being
wrapped in a simple function -- neither of the integer values are
initialised, so it has undefined behaviour on the line after "// making"
comment.

If we look at it as two disconnected fragments (declarations first and
then the loops next), then the code seems OK, and I presume it has no
errors that your compiler would report. The "lag" could be attributed
to the optimiser taking a shot at the nested loops.

int ***neuralNetwork;
int width;
int hight;
int depth;

// making
neuralNetwork = new int **[width];
for (int i=0; i < width; i++)
{
neuralNetwork[i] = new int *[hight];
for (int j=0; j < hight; j++)
neuralNetwork[i][j] = new int[depth];
}
// filling
for (int i = 0; i < depth; i++)
for (int k = 0; k < hight; k++)
for (int j = 0; j < width; j++)
neuralNetwork[j][k][i] = 0;
// deleting
for (int i=0; i < width; i++)
{
for (int j=0; j < hight; j++)
delete [] neuralNetwork[i][j];
delete [] neuralNetwork[i];
}
delete [] neuralNetwork;

V
Aug 5 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.