Memory allocation problem C/Cpp Windows critical error
Posted
by Andrew
on Stack Overflow
See other posts from Stack Overflow
or by Andrew
Published on 2010-03-21T12:15:37Z
Indexed on
2010/03/21
12:21 UTC
Read the original article
Hit count: 387
Hi! I have a code that need to be "translated" from C to Cpp, and i cant understand, where's a problem. There is the part, where it crashes (windows critical error send/dontSend):
nDim = sizeMax*(sizeMax+1)/2;
printf("nDim = %d sizeMax = %d\n",nDim,sizeMax);
hamilt = (double*)malloc(nDim*sizeof(double));
printf("End hamilt alloc. %d allocated\n",(nDim*sizeof(double)));
transProb = (double*)malloc(sizeMax*sizeMax*sizeof(double));
printf("End transProb alloc. %d allocated\n",(sizeMax*sizeMax*sizeof(double)));
eValues = (double*)malloc(sizeMax*sizeof(double));
printf("eValues allocated. %d allocated\n",(sizeMax*sizeof(double)));
eVectors = (double**)malloc(sizeMax*sizeof(double*));
printf("eVectors allocated. %d allocated\n",(sizeMax*sizeof(double*)));
if(eVectors) for(i=0;i<sizeMax;i++) {
eVectors[i] = (double*)malloc(sizeMax*sizeof(double));
printf("eVectors %d-th element allocated. %d allocated\n",i,(sizeMax*sizeof(double)));
}
eValuesPrev = (double*)malloc(sizeMax*sizeof(double));
printf("eValuesPrev allocated. %d allocated\n",(sizeMax*sizeof(double)));
eVectorsPrev = (double**)malloc(sizeMax*sizeof(double*));
printf("eVectorsPrev allocated. %d allocated\n",(sizeMax*sizeof(double*)));
if(eVectorsPrev) for(i=0;i<sizeMax;i++) {
eVectorsPrev[i] = (double*)malloc(sizeMax*sizeof(double));
printf("eVectorsPrev %d-th element allocated. %d allocated\n",i,(sizeMax*sizeof(double)));
}
Log:
nDim = 2485 sizeMax = 70
End hamilt alloc. 19880 allocated
End transProb alloc. 39200 allocated
eValues allocated. 560 allocated
eVectors allocated. 280 allocated
So it crashes at the start of the loop of allocation. If i delete this loop it crashes at the next line of allocation. Does it mean that with the numbers like this i have not enough memory??
Thank you.
© Stack Overflow or respective owner