delete []

Started by
7 comments, last by Greg K 21 years, 4 months ago
When using delete, what possible errors could you get? I try to free some memory using delete and it gives me an assert error "Damage after Normal block #1641 : 00DFAAD0" (the wording may be a bit diff but the numbers are the same). The memory pointer is the correct pointer to the memory I am trying to free. I output the address to a file directly after allocation and then again just before I free it and it is the same pointer all three times (in the assert as well). Any suggestions? -Greg
Advertisement
You''re overwriting the bounds of an array, and buggering up memory after it.

E.g.

  int* pArray = new int[4];for(int i=0; i<=4; ++i)   pArray[i] = i*2;  


HTTP 500 x4

Member of the Unban Mindwipe Society (UMWS)
>>I output the address to a file directly after allocation and then again just before I free it and it is the same pointer all three times (in the assert as well).<<

drop some code so we can see.
by any chance do you free the memory in another function?

also what did you create it with? new? or malloc/calloc/realloc?
is the memory in question an array or single entity?
(ie. int *intPtr = new int[10] or int *intPtr = new int)

Beginner in Game Development?  Read here. And read here.

 

I was reading data from a file into the array of WORDs and it was overflowing. I was using fscanf(). What % thing should I use to read in a short (or a WORD)
-Greg
There doesn''t appear to be one in the MSDN.
You could just do this:

  char szBuffer[32]WORD wVal;fscanf("%31s",szBuffer);   // I think thats rightwVal = (WORD)atoi(szBuffer);  



HTH
HTTP 500 x1

Member of the Unban Mindwipe Society (UMWS)
(note: show code)

since you''re using C you should be using free( ) not delete[] (gathering from what you told me). also you can use %i or %d for short i believe. and make the array bigger

merry christmas

Beginner in Game Development?  Read here. And read here.

 

@Alpha_ProgDes: Sorry, I thought I explained it well enough without showing code.

@Evil Bill: Thanks. That is what I am going to do now except I am just inputting it straight into an int and then typecasting it to a word.
-Greg
Alpha_ProgDes:
%i: "Decimal, hexadecimal, or octal integer. Pointer to int."
%d: "Decimal integer. Pointer to int."

Greg K: D''oh! Sorry, me being blonde again.

Member of the Unban Mindwipe Society (UMWS)
the face says it all.
back to studying....

Beginner in Game Development?  Read here. And read here.

 

This topic is closed to new replies.

Advertisement