[Rd] persistent C++ objects

From: Tamas K Papp <tpapp_at_princeton.edu>
Date: Mon 24 Jul 2006 - 18:50:40 GMT


I am trying to create an R interface for Dynare++ [1], a k-order solver for rational expectation models. I would like some advice on how to glue the C++ code to R.

In C++, it works the following way:

An R interface could work this way:

modeleq <- dynare_expand(... model description ...)
result1 <- dynare_substitute(modeleq, par1)
result2 <- dynare_substitute(modeleq, par2)

So the user needs to see something in R that corresponds to a C++ object that remains in the memory between calls. What is the proper way to do that? Pass a pointer? How do I handle that in the .C() calls, convert it to long int? My C++ programming knowledge is pretty limited, suggestions and examples would be appreciated.

The rest (using extern "C" constructs as described in "Writing R Extensions") is pretty clear, except how to make R call the destructor of the object when the garbage collector removes it.



[1] http://www.cepremap.cnrs.fr/juillard/mambo/index.php?option=com_content&task=view&id=53&Itemid=86

R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Tue Jul 25 04:51:04 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Mon 24 Jul 2006 - 22:30:36 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.