|
Boost : |
From: Zach Laine (whatwasthataddress_at_[hidden])
Date: 2019-06-27 15:46:47
On Wed, Jun 26, 2019, 11:12 PM JeanHeyd Meneide via Boost <
boost_at_[hidden]> wrote:
> On Wed, Jun 26, 2019 at 11:05 PM Gavin Lambert via Boost <
> boost_at_[hidden]> wrote:
>
> > On 27/06/2019 13:52, Bagaskoro Kang wrote:
> > > the creator apis have two out params: Interface** pointer and
> > unsigned*
> > > size and the destroyer functions must be called with pointer and the
> > size.
> > >
> > > Interface** obj;
> > > unsigned size;
> > > int ret = Create(... ... ... &obj, &size);
> > >
> > > and then we need to call a Release(obj, size) if the ret is success.
> > >
> > > I do not think I can use the out_ptr with these APIs ???
> >
> >
> struct sized_deleter {
> unsigned size;
> ...
> };
>
> using bop = boost::out_ptr;
>
> std::unique_ptr<Interface, sized_deleter> p_obj;
> int ret = Create(..., bop::out_ptr(p_obj), &p_obj.get_deleter().size)
> if (LIBNAME_HAS_FAILED(ret)) {
> throw std::runtime_error("deep sadness");
> }
>
> This example is less pretty because I'm putting the size in the deleter,
> but it works.
>
>
> > > also we call the Linux kernel C API posix_memalign() and we assign to
> > > unique_ptr. is not possible to use out_ptr with ?
> > >
> > > std::unique_ptr<Numf, DoFree> upNumf;
> > > void * pNumf;
> > > int ret = posix_memalign(&pNumf, 64, nNumf);
> > > if (!ret)
> > > upNumf.reset((Numf*)pNumf);
> >
>
> using bop = boost::out_ptr;
>
> std::unique_ptr<Numf, DoFree> upNumf;
> int ret = posix_memalign(bop::out_ptr<void*>(upNumf), 64, nNumf);
> if (ret != 0) {
> throw std::runtime_error("something went wrong, but at least we're not
> leaking memory here.");
> }
>
> Casting support is built in to the API: you can go from strongly typed
> pointers to void**, or other related pointers by passing the type as a
> template argument.
>
These seem like they would make good examples for the docs.
Zach
>
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk