On 6 December 2014 at 21:41, Jeroen Ooms wrote: | On Fri, Dec 5, 2014 at 12:54 AM, Romain François | <rom...@r-enthusiasts.com> 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 destroys the handle after the function returns, even though | the handle is referenced by the XPtr that I just created. I was hoping | that it would automatically be protected as long as the EXTPTRSXP is | pointing to it, but that does not seem to be the case. | | I am currently working around it by maintaining a list of handles in | the global scope, but it would be more elegant if R(cpp) would take | care of it.
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: http://en.wikibooks.org/wiki/More_C++_Idioms/Resource_Acquisition_Is_Initialization http://programmers.stackexchange.com/questions/29692/whats-raii-examples Dirk -- http://dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org _______________________________________________ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel