Re: about new operator
- From: David Wilkinson <no-reply@xxxxxxxxxxxx>
- Date: Sat, 29 Apr 2006 08:36:53 -0400
harshalshete@xxxxxxxxx wrote:
hi group here is my second problem
i am allocating a buffer
char *p = new char[1024];
p = regBuffer.GetBuffer(regBuffer.GetLength());
and after doing all the work i am trying to free that memory with
1)delete []p;
p=NULL;
2)delete p;
p=NULL;
but in both the cases i get error as
debug assertion failed
File dbgheap.c
Line: 1011
Expression: _CrtIsValidHeapPointer(pUserData)
can anybody tell me what's wrong with this code
harshalshete:
What do you expect? Your have overwritten your variable p (which was pointing to your new'd memory) with something else, so you cannot use it to free the memory any more. You don't need to allocate any memory here; you are getting it from regBuffer (which is a CString, yes?).
BTW when you use array new, you must use array delete
char *p = new char[1024];
// don't reassign to p !!!
delete [] p;
David Wilkinson
.
- References:
- about new operator
- From: harshalshete@xxxxxxxxx
- about new operator
- Prev by Date: about new operator
- Next by Date: Re: use a keyboard in our application
- Previous by thread: about new operator
- Next by thread: Re: about new operator
- Index(es):
Relevant Pages
|