Boost logo

Boost :

From: Bagaskoro Kang (bagaskoro.kang_at_[hidden])
Date: 2019-06-27 03:13:32


Gavin Lambert:

> 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 ???
>
> I assume that's a typo and should be "Interface* obj".
>
> You wouldn't be able to use it out of the box with that interface, but
> if you define a custom smart pointer (which just wraps std::unique_ptr
> with a deleter that passes the size, for example) then you could
> probably get it to work.
>
>
can you show me the example of this?

> Spreading the responsibilities over two parameters does make things more
> tricky, though. If it's at all possible to remove the requirement to
> pass size around, you should do that instead. (It's not normally needed
> for array allocation, for example.)
>
>
it is not possible to remove it

> > 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);
>
> Why not use std::aligned_storage or put alignas on the class instead?
>
>
how do you do that ~ what will the new code be like?


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