• Advertisement

Archived

This topic is now archived and is closed to further replies.

delete []

This topic is 5506 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
>>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)

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
(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

Share this post


Link to post
Share on other sites
@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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

  • Advertisement