Skip to content
Prev 2686 / 10988 Next

[Rcpp-devel] wrap returned pointer to class

Hi!

I just figured a way to deal with pointers to objects in memory which I receive by calling whatever function of a third-party library. The problem is warp it into a suitable object. My approach which does a nice job is:

  template <>
  SEXP wrap( B* const& mb ) {
    typedef result<B> ptr_wrap_t;
    return XPtr<ptr_wrap_t>(new ptr_wrap_t(mb));
  }

Here, B* is returned from a function I call. Now the idea is to create a result-object which contains the pointer and hand that to XPtr. This makes XPtr happy as it is now authoritative over the life of the result-object. How about enabling this for *all* pointers by default which get passed into R space?

Cheers,

Sebastian

Am 02.08.2011 um 11:28 schrieb romain at r-enthusiasts.com: