Re: free()
- From: Chris Dollin <chris.dollin@xxxxxx>
- Date: Wed, 14 Feb 2007 12:01:19 +0000
Richard Heathfield wrote:
Chris Dollin said:
<snip>
When goats are given additional pointer members (such as arms),
freeing a goat will have to deal with this. I find it easiest
to have a goatFree function right from the start, so that
I don't have to go free(aGoat)-hunting and change it.
Yes, likewise, which is why I write the destructor in the way I showed
you.
It might not only be goats that use trollguns, and anyway there may
be other circumstances where you need to destroy a trollgun other
than the one where you are destroying - sorry! deleting - a goat.
Yes - but the same argument applies: either I'm going to destroy
the place that pointed to the gun, so no point nulling it, or I'm
going to give it a new value, so no point nulling it.
No, there's another possibility - that the entity that had the gun no
longer has a gun (I dunno, perhaps the troll rips out the arm that was
holding it or something), and thus NULL is an appropriate value for
that pointer.
Yes - sometimes the new value is null.
Sometimes, rather than nulling the pointer because you're freeing it
(well, the pointed-to object), you're freeing the pointer (ditto)
because you're nulling it [1].
For me, this is often the case, (not that I use trollguns
very often) - objects gain and lose other objects with careful abandon.
Indeed.
[1] And you know this is the only surviving usable reference.
--
Chris "electric hedgehog" Dollin
"People are part of the design. It's dangerous to forget that." /Star Cops/
.
- References:
- free()
- From: dbansal
- Re: free()
- From: santosh
- Re: free()
- From: Racaille
- Re: free()
- From: santosh
- Re: free()
- From: Richard Bos
- Re: free()
- From: Ian Collins
- Re: free()
- From: Christopher Benson-Manica
- Re: free()
- From: Richard Heathfield
- Re: free()
- From: Beej
- Re: free()
- From: Chris Dollin
- Re: free()
- From: Richard Heathfield
- Re: free()
- From: Chris Dollin
- Re: free()
- From: Richard Heathfield
- Re: free()
- From: Chris Dollin
- Re: free()
- From: Richard Heathfield
- free()
- Prev by Date: Re: free()
- Next by Date: Re: free()
- Previous by thread: Re: free()
- Next by thread: Re: free()
- Index(es):
Relevant Pages
|