out_ptr review is extended until Wednesday, July 10
We don't have enough reviews yet, so we're extending the review by two weeks. Please review this small and useful library!
From the original announcement:
The formal review of JeanHeyd Meneide's out_ptr library starts Sunday, June 16th and ends on Wednesday, June 26th. out_ptr is a library for making it easy to interoperate between smart pointers and traditional C-style initialization and allocation interfaces. It also enables doing so in a way that allows library authors to opt into speed optimizations for their smart pointers that give them performance equivalent to typical C pointers (see benchmarks ( https://github.com/ThePhD/out_ptr/blob/master/docs/out_ptr/benchmarks.adoc) and the Standard C++ proposal for more details). Online docs can be found here: https://github.com/ThePhD/out_ptr/blob/master/docs/out_ptr.adoc The GitHub repository is available here: https://github.com/ThePhD/out_ptr Also, there is an associated standards proposal: https://thephd.github.io/vendor/future_cxx/papers/d1132.html We encourage your participation in this review. At a minimum, please state: - Whether you believe the library should be accepted into Boost - Your name - Your knowledge of the problem domain You are strongly encouraged to also provide additional information: - What is your evaluation of the library's: * Design * Implementation * Documentation * Tests * Usefulness - Did you attempt to use the library? If so: * Which compiler(s)? * What was the experience? Any problems? - How much effort did you put into your evaluation of the review? All issues discussed during this review will be tracked on the library's GitHub issue tracker at https://github.com/ThePhD/out_ptr/issues. Zach
Zach Laine dia menulis
We don't have enough reviews yet, so we're extending the review by two weeks.
Please review this small and useful library!
we have C apis set that we call from C++ which do not work with this
library?
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 ???
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
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. 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.)
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
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?
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
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?
Dear Bagaskoro Kang,
I apologize, I thought my previous message got the example through to
you, but it seems like it did not. Here is the example using out_ptr to do
what you describe:
struct SizedDeleter {
size_t size = 0;
void operator()(Interface* obj) const {
DeleteBusInterface(obj, size);
}
};
using bop = boost::out_ptr;
size_t& size_ref = p_obj.get_deleter().size;
std::unique_ptr
On Wed, Jun 26, 2019 at 11:05 PM Gavin Lambert via Boost < boost@lists.boost.org> 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
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
upNumf; void * pNumf; int ret = posix_memalign(&pNumf, 64, nNumf); if (!ret) upNumf.reset((Numf*)pNumf);
using bop = boost::out_ptr;
std::unique_ptr
On Wed, Jun 26, 2019, 11:12 PM JeanHeyd Meneide via Boost < boost@lists.boost.org> wrote:
On Wed, Jun 26, 2019 at 11:05 PM Gavin Lambert via Boost < boost@lists.boost.org> 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
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
upNumf; void * pNumf; int ret = posix_memalign(&pNumf, 64, nNumf); if (!ret) upNumf.reset((Numf*)pNumf); using bop = boost::out_ptr;
std::unique_ptr
upNumf; int ret = posix_memalign(bop::out_ptr (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
On 6/27/19 6:46 PM, Zach Laine via Boost wrote:
On Wed, Jun 26, 2019, 11:12 PM JeanHeyd Meneide via Boost < boost@lists.boost.org> wrote:
using bop = boost::out_ptr;
std::unique_ptr
upNumf; int ret = posix_memalign(bop::out_ptr (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.
Note that in case of posix_memalign you're not leaking memory even without out_ptr.
participants (5)
-
Andrey Semashev
-
Bagaskoro Kang
-
Gavin Lambert
-
JeanHeyd Meneide
-
Zach Laine