Boost logo

Boost :

From: Alan Bellingham (alan_at_[hidden])
Date: 2003-05-14 06:07:03


Markus:

>In one of Herb Sutters articles I saw that
>after deleting a pointer (a pimpl) he assigns 0 afterwards
>which seems to me like a good idea.
>(see e.g. http://www.gotw.ca/gotw/028.htm or http://tinyurl.com/bq8o)
>
>Maybe there is a good reason (efficiency?)
>why checked_delete omits this extra step.
>Please explain.
>
>template<class T> inline void checked_delete(T * x)
>{
> typedef char type_must_be_complete[sizeof(T)];
> delete x;
> // why not ?
> x = 0;
>}

Well, it's pretty pointless, though an reasonable optimiser will spot
that the value x is never used after that last assignment, and lose it.
Would we want to put extra code into Boost just to get a slower compile
speed and possibly slower execution speed? Probably not.

It's reasonable to promote strictly unnecessary safety code in user
code, but when it comes to a library, we want it to be as efficient as
possible consistent with safety. In this case, we rigourously inspect
the code (by eye, and by linting) and determine that the line in
question actually is unnecessary.

Alan

-- 
Alan Bellingham

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk