Skip to main content
GameDev.net gamedev.net
🔒 Locked

delete []

Started by Greg K Dec 24, 2002 at 1:02 PM 7 replies 550+ views
Original Post
Greg K
Greg K
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
Evil Bill
Evil Bill
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)
Alpha_ProgDes
Alpha_ProgDes
>>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.  
Greg K
Greg K
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
Evil Bill
Evil Bill
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 right

wVal = (WORD)atoi(szBuffer);



HTH
HTTP 500 x1

Member of the Unban Mindwipe Society (UMWS)
Alpha_ProgDes
Alpha_ProgDes
(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.  
Greg K
Greg K
@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
Evil Bill
Evil Bill
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)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.