Re: [Rcpp-devel] Rcpp and ExternalPtr

2014-12-08 Thread Tim Keitt
On Mon, Dec 8, 2014 at 10:34 AM, Dirk Eddelbuettel wrote: > > On 8 December 2014 at 09:58, Tim Keitt wrote: > | > | > | On Sun, Dec 7, 2014 at 4:52 AM, Dirk Eddelbuettel > wrote: > | > | > | > | What you are after, if I understand it correctly, is (close to) a > common > | and > | we

Re: [Rcpp-devel] Rcpp and ExternalPtr

2014-12-08 Thread Dirk Eddelbuettel
On 8 December 2014 at 09:58, Tim Keitt wrote: | | | On Sun, Dec 7, 2014 at 4:52 AM, Dirk Eddelbuettel wrote: | | | | What you are after, if I understand it correctly, is (close to) a common | and | well studied idiom called 'RAII': Resource Acquisition is Initialization. |

Re: [Rcpp-devel] Rcpp and ExternalPtr

2014-12-08 Thread Tim Keitt
On Sun, Dec 7, 2014 at 4:52 AM, Dirk Eddelbuettel wrote: > > > What you are after, if I understand it correctly, is (close to) a common > and > well studied idiom called 'RAII': Resource Acquisition is Initialization. > Two > quick links, and you will find many more: > > I don't know if this exam

Re: [Rcpp-devel] Rcpp and ExternalPtr

2014-12-07 Thread Dirk Eddelbuettel
On 6 December 2014 at 21:41, Jeroen Ooms wrote: | On Fri, Dec 5, 2014 at 12:54 AM, Romain François | wrote: | > | > You are looking for XPtr. | | Thanks guys, exactly what I needed indeed. One follow-up question: | | Is there a way to use the XPtr object to prevent the c++ object it | points to

Re: [Rcpp-devel] Rcpp and ExternalPtr

2014-12-07 Thread Dirk Eddelbuettel
On 5 December 2014 at 05:37, JJ Allaire wrote: | I think the XPtr class is what you are looking for: Indeed. XPtr is perfect for managing external resources. | http://www.r-bloggers.com/external-pointers-with-rcpp/ And there are four Rcpp Gallery posts highlighted as a result of a you search

Re: [Rcpp-devel] Rcpp and ExternalPtr

2014-12-06 Thread Jeroen Ooms
On Fri, Dec 5, 2014 at 12:54 AM, Romain François wrote: > > You are looking for XPtr. Thanks guys, exactly what I needed indeed. One follow-up question: Is there a way to use the XPtr object to prevent the c++ object it points to from going out of scope? It seems like the c++ garbage collector d

Re: [Rcpp-devel] Rcpp and ExternalPtr

2014-12-05 Thread JJ Allaire
I think the XPtr class is what you are looking for: http://www.r-bloggers.com/external-pointers-with-rcpp/ On Fri, Dec 5, 2014 at 2:45 AM, Jeroen Ooms wrote: > Does Rcpp provide some elegant way to let the R user manage persistent > c++ objects that have no R type (e.g. internal handles or sess

Re: [Rcpp-devel] Rcpp and ExternalPtr

2014-12-05 Thread Romain François
You are looking for XPtr. https://github.com/RcppCore/Rcpp/blob/master/inst/include/Rcpp/XPtr.h It is a template class whose first parameter is the class of the raw pointer you are dealing with, let’s call it T. You can create an external pointer using something like : XPtr xp( new T(...) )

[Rcpp-devel] Rcpp and ExternalPtr

2014-12-04 Thread Jeroen Ooms
Does Rcpp provide some elegant way to let the R user manage persistent c++ objects that have no R type (e.g. internal handles or sessions of some sort)? In C, I would use R_MakeExternalPtr to create a ptr SEXP that the user can pass from one R function to another. This also makes it easy to add a