Note that there are some explanatory texts on larger screens.

plurals
  1. POCorrupted heap error when declaring a double* array
    primarykey
    data
    text
    <p>I'm currently working on finding the sum of squared distances of two matricies, the data is held in double* arrays. the first of them stays the same while the other is cycled through using a function that returns a 32x32 array between two indices.</p> <p>However when i try and call "getTile(d,e)" after the first incrementation of "e" it throws a heap corruption exception:</p> <pre><code>double* Matrix::ssd(int i, int j, Matrix&amp; rhs){ double sum = 0, val = 0; int g = 0, h=0; double* bestMatch = new double[32*32]; double* sameTile = new double[32*32]; double* changeTile = new double[32*32]; for(int x = i-32; x &lt;i; x++){ for(int y = j-32; y &lt;j; y++){ sameTile[g*32+h] = data[x*N+y]; h++; }g++; h = 0; } system("pause"); for(int d = 32; d&lt;=512; d+=32){ for(int e = 32; e&lt;=512; e+=32){ changeTile = rhs.getTile(d,e); for(int out = 0; out &lt; 32; out++){ for(int in = 0; in &lt; 32; in++){ val = sameTile[out*32+in] - changeTile[out*32+in]; val = val*val; sum = sum + val; } } cout &lt;&lt; sum &lt;&lt; endl; sum = 0; val = 0; system("pause"); } } </code></pre> <p>The getTile(int i, int j) function:</p> <pre><code>double* Matrix::getTile(int i, int j){ double* tile = new double[32*32]; int g = 0; int h = 0; for(int x=i-32; x&lt;i; x++){ for(int y=j-32; y&lt;j; y++){ tile[g*32+h] = data[x*N+y]; h++; } cout &lt;&lt; endl; g++; } return tile; } </code></pre> <p>I believe the error occurs with the allocation of memory in the changeTile double*?</p> <p>Any help would be very much appreciated.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload