Boost logo

Boost Users :

From: Sohail Somani (sohail_at_[hidden])
Date: 2008-05-16 12:28:38


Kevin Martin wrote:
> I have just discovered to my delight that you can use shared_ptr with
> a null deleter to pass around stack based objects. This is great
> because a function shouldn't care whether a parameter passed to it is
> on the heap or stack. So I can write general functions to accept a
> shared_ptr and if I have to pass a stack based object I can just pass
> a null deleter.

I was recently torn between doing this or thinking whether I'm doing it
wrong. I'm still not sure whether using shared pointers everywhere with
null deleters for stack allocated objects is The Right Thing. It kind of
defeats the purpose of shared_ptr which is to ensure that the lifetime
of the pointer is guaranteed for you. With null deleters, maintenance
programmers may do the wrong thing (stuff something in an event queue
deep down, for example.)

If anyone has any opinion (for or against) please shout!

-- 
Sohail Somani
http://uint32t.blogspot.com

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net