Hi,
I got some major error from the debugger of ms vs 2005 with this code:
Code:
int **idArray; /*This array contains the pointer to the x and y arrays*/
int **rangeArray; /*This array contains the range*/
idArray = new int *[numberOfNodes*2];/*Create array of pointers to the x and y arrays of int*/
memset(idArray,0,sizeof(int *)*(numberOfNodes*2));
rangeArray = new int *[numberOfNodes];/*Create array of pointers to the range of the nodes*/
memset(rangeArray,0,sizeof(int *)*(numberOfNodes));
for(int i=0;i<numberOfNodes*2;i++) {
idArray[i] = new int[simulationTime];/*Create arrays of x and y position*/
memset(idArray[i],0,sizeof(int)*(simulationTime));
}
for(int i=0;i<numberOfNodes;i++) {
rangeArray[i] = new int[simulationTime];/*Create arrays of range*/
memset(rangeArray[i],0,sizeof(int)*(simulationTime));
}
*(rangeArray[(currentId+2)/2 - 1]+counter) = range; /*Put the rage in for the time interval*/
*(idArray[currentId]+counter) = (int) (subInt*cos((direction-0)*PI/180) + *(idArray[currentId]+counter-1)); /*Puts in the x position*/
*(idArray[currentId+1]+counter) = (int) (subInt*sin((direction-0)*PI/180) + *(idArray[currentId+1]+counter-1)); /*Puts in the y position*/
counter++;
The code is basically calculating position and range for different times. CurrentId is always less that numberOfNodes, counter does not go beyond simulationTime.
To delete the arrays, I used this code:
Code:
if(rangeArray != NULL) {
for(int i=0;i<numberOfNodes;i++) {
delete[] rangeArray[i];
}
delete[] rangeArray;
rangeArray = NULL;
}
if(idArray != NULL) {
for(int i=0;i<numberOfNodes*2;i++) {
delete[] idArray[i];
}
delete[] idArray;
idArray = NULL;
}
Whenever the debugger hits the line delete[] rangeArray[i]; I get the following error:
Debug error
program ...
HEAP CORRUPTION DETECTED: after normal block (#128) at 0x003682F0. CRT detected that the application wrote to memory after end of heap buffer.
I am completely confused. I thought memory was being deallocated at this point. So the program should not be writing any additional stuff to the heap. Hopefully somebody can point me in the right direction for this. Thanks
Amish