So I have written this method making use of double** structures, being used for storing values in a matrix like structure.
Like this:
1 2 3 4 5 6 7
|
double **allocDouble(size_t x,size_t y){
double **ret = new double*[x];
for(size_t i=0;i<x;i++){
ret[i] = new double[y];
}
return ret;
}
|
Then I run this method calculating a lot of stuff through many iterations. At every iteration storing the values in my matrix M. And it works fine, however when I start doing something called bootstrapping, where I sample rows with replacement from my input data, which is in the shape of a matrix also, I sometimes get this error, where the entries of my matrix M, are claimed not to be allocated, even though I have used these entries through many iterations.
So does anyone have any idea why this can be? Should one not overwrite these entries too many times? Or can a double be too large for an entry?
It also has to be said that with other input data the method runs fine. The method might run fine with one seed and not with another seed, for the same data. Implying that it somehow depends on which rows are sampled with the bootstrap.
Or I am sorry if this is far too vague? Do you have any idea how I could look further into this issue?
The error I get is:
==83081== Invalid write of size 8
==83081== at 0x403147: main
==83081== Address 0x48d012a8 is 16 bytes after a block of size 40 alloc'd
==83081== at 0x4C2E80F: operator new[](unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==83081== by 0x402CD0: main