memory related crash in vc++
hai to all in this group..
i am very thankfull to alll thge members in this group.
i have improved a lot after joining in this group..
my project is workig 3-6 times well but after that it is crashing...displaying message like "THE INSTRUCTION AT MEMORY ''0FF656GD"REFFRENCED AT MEMORY "05FFFF" AND THE MEMORY COULD NOT BE READOR WRITTEN"
what is the reason fo this probelm i am unabel to identify problem. what is the reason and how to solve it..
# 1 Re: memory related crash in vc++
Hi,
looks like you have a dangling pointer somewhere. Make sure all dynamic memory is
a) initialized
b) allocated (if you want to use val[10] make sure val has at least size 11)
c) freed properly
new --> delete // single object
new[] --> delete[] // array
malloc --> free // C-style allocation
I would strongly recommend to consider STL alternatives. Saves a lot of grieve and bodily harm!
For most purposes vectors/lists/maps of the STL are dynamic enough and you don't have the headache of allocating and keeping track of what to free when. You still can get your error when you do something like that:
vector<long> vLong;
vLong.resize(5);
vLong[10] = 567; // <<< Error
Hope that help. If in doubt, post the naff code...
Cheers,
D
# 2 Re: memory related crash in vc++
Adding to what Dieter has said, it would be very helpful if you posted some of the code that causes the crash. It certainly has a memory related bug, but it's hard to tell which bug exactly without seeing the code.
Danny at 2007-11-11 21:01:09 >

# 4 Re: memory related crash in vc++
for(i=0;i<nPrimrowblks;i++)
{
for(int j=0;j<nPrimcolblks;j++)
{
for(int row=i*PRIMBLKSIZ;row<(i+1)*PRIMBLKSIZ;row++)
{
for(int col=j*PRIMBLKSIZ;col<(j+1)*PRIMBLKSIZ;col++)
{
int pixelValue = PixelDirImg[row][col];
primaryHist[i][j][pixelValue] +=OccuranceImg[row][col];
}
}
}
}
int ***standardHist = new int** [nStdrowblks];
for(i=0;i<nStdrowblks;i++)
{
standardHist[i] = new int* [nStdcolblks]; //Declaration of Standard Histogram
for(int j=0;j<nStdcolblks; j++)
standardHist[i][j] = new int[9];
}
for(i=0;i<nStdrowblks;i++)
for(int j=0;j<nStdcolblks;j++) //Initializing Standard Histogram
for(int k=0;k<9;k++)
standardHist[i][j][k] = 0;
//and i ma deleting like this..
for(i=0;i<nStdrowblks;i++)
{
for(int j=0; j<nStdcolblks; j++)
delete[] standardHistTemp[i][j];
delete[] standardHistTemp[i];
}
delete [] standardHistTemp;
standardHistTemp=NULL;
for(i=0;i<nStdrowblks;i++)
{
for(int j=0; j<nStdcolblks; j++)
delete[] standardHist[i][j];
delete[] standardHist[i];
}
delete [] standardHist;
standardHist=NULL;
//this code fro dll my programm using..
# 5 Re: memory related crash in vc++
There's probably a memory related a bug somewhere in this code but before you try to find it, I think it would be better to consider a re-design. Why do you need something like int***? Isn't it possible to create a static the-dimensional array and thus avoid the dynamic allocation/deallocation of memory?
Danny at 2007-11-11 21:04:06 >

# 6 Re: memory related crash in vc++
Hi venky,
some notes here...
firstly am assuming standardHistTemp is allocated somewhere in the code...
If you are using MVC++, you can find out possible areas of memory corruption easily...Debug your application...when it breaks , the assembler shall open up...You can check which variable was being accessed there...
...also as Danny says above, rewrite is a good idea, as the manner in which allocations and variable scopes are used is pretty haphazard...