Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Blog | Linux Links | Bling | About BLU

BLU Discuss list archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

C++ use of Malloc/Realloc and Free



> On Sun, Jun 22, 2003 at 04:15:57PM -0400, Jerry Feldman wrote:
> > > So I agree with you that using malloc/free/realloc can be quite
> > > dangerous, there are some occasional times where the risks outweigh
> > > the danger. 
> > Yes, you are quite correct. The bottom line is that the programmer must
> > understand the issues. 
> 
> Ok, I'll bite.  What are the issues?  I've not done much C++
> programming, but I'm curious...
> 
> - -- 
> Derek D. Martin

I don't think it's very complicated, but as always, one needs to be aware of
what happens.  Just make sure that if you allocate memory within a class, that
the destructor for the class frees it.  Sort of like making sure that memory 
allocated by a function is released before it returns.  If pointers to 
allocated memory are passed around between classes, the same problems
exist as for passing pointers to allocated memory between C functions.  One
doesn't want it freed in a destructor and then used, or have it left dangling.




BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org