|
From: Abhijit S. <mu...@gm...> - 2002-09-05 16:19:28
|
----- Original Message ----- From: "Carlos García del Monte" <cg...@wo...> To: "dev-cpp-users-list" <dev...@li...> Sent: Wednesday, September 04, 2002 12:39 AM Subject: Re: [Dev-C++] realloc The point is that with realloc, if it succeeds the original memory pointed by the argument pointer is freed and so you can forget it and work with the new, but if it fails, then the memory pointed to by the argument pointer remains valid, and if you use that same pointer as return value, then you get that the pointer is no more pointing to that piece of still valid memory, and, how you free it? it will be annoying your program. The moral of the story is, don't use the same pointer as argument and return value of realloc. If it fails, if(!returnpointer) work with the original and free(original) if it succeeds else work with the new and forget the old. --------------------------- Yeah, sorry for the leads-to-memory-leak-type mistake (which I hate and detest and avoid at all costs :). No way under C++ to realloc() a new'ed pointer, is there? (Apart from writing your own `renew' function) ___________________________________________________________ Abhijit Shylanath E-mail: mu...@gm... || ibr...@bi... Web-site: http://mudeth.tripod.com/ |