Boost logo

Boost :

From: Sohail Somani (s.somani_at_[hidden])
Date: 2006-12-01 17:00:57


> -----Original Message-----
> From: boost-bounces_at_[hidden]
> [mailto:boost-bounces_at_[hidden]] On Behalf Of Tobias Schwinger
> >>I was referring to the file pointer, which is pretty much the
> >>only "C resource" I use.
> >>You're right when it comes to malloc/free, of course - but do
> >>we really need it?
> >
> > Anytime you deal with C atleast, the answer is yes.
> >
>
> I doubt it's good practice for a C library to allocate stuff
> and hand it
> to the user who has to then free it or to free stuff that
> comes from the
> user...
>
> The other cases are:
> a) it's up to the user to obtain the memory, so new/delete will work
> b) the library provides ctor/dtor routines, so custom
> deleters are needed

Most C libraries have make_X/free_X pairs. So a typical C call could
look like:

...
struct T * c = make_T(args);
do_stuff_with_a_T(c);
free_T(c);
...

Which I would like to replace with:

...
typedef some_ptr<T,Deleter<free_T> > T_ptr;
T_ptr c(make_T(args));
do_stuff_with_a_T(c.get());
...


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