Boost logo

Boost Users :

From: Reid Sweatman (drunkardswalk_at_[hidden])
Date: 2005-01-08 15:38:39


> -----Original Message-----
> From: boost-users-bounces_at_[hidden]
> [mailto:boost-users-bounces_at_[hidden]] On Behalf Of Ben
> Hutchings
> Sent: Thursday, January 06, 2005 6:25 AM
> To: boost-users_at_[hidden]
> Subject: Re: [Boost-users] Re: why doesn't scoped_ptr have a custom
>
>
> Pablo Aguilar wrote:
> > Thanks for your reply...
> >
> > You're right, "reset" would delete the pointer... but when you're
> > getting
> > rid of a pointer obtained from a factory, like I was in my
> case, pointers
> > don't always get disposed of using delete, but rather
> another function (like
> > p->release())
> >
> > And rather than writing special purpose smart pointers for
> each type
> > of
> > deleting function (p->dispose(), p->release(),
> api_function_free(p), etc..)
> > you can use shared_ptr with a custom deleter (here:
> > mem_fn(&pointer_type::dispose) or bind(&api_function_free, _1))
>
> In some cases you can avoid the space and time overhead of
> shared_ptr by
> using a smart pointer template for which the custom deleter is a
> template argument. In fact you can get even more general than that
> quite easily; I have a class template called auto_handle which with
> minimal work can be used to encapsulate all kinds of things
> with custom
> deleters, including Windows handles and POSIX file descriptors.

Good point. Probably most developers in this group have done something like
that; mine is an editor macro customized for my favorite editor, I use it so
often. It lets me supply the parameterizations using an OS-specific, but
minimally-intrusive interface as I edit.

Reid


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