[Rcpp-devel] R_PreserveObject and R_ReleaseObject

Dirk Eddelbuettel edd at debian.org
Thu Aug 16 17:52:17 CEST 2018


On 16 August 2018 at 08:43, Kevin Ushey wrote:
| I think the main problem is that it's easy to use your class incorrectly.
| For example:
| 
| - What happens if your map is destructed? The SEXPs it is handling are
| effectively leaked.
| - What if you copy your map? Since SEXPs are pointers, you now have two
| maps containing the same pointers, and if you were to attempt to remove a
| SEXP from both maps problems would occur.
| 
| Rather than attempting to manage the lifetime of these R objects in your
| map's methods, it's better to have wrapper classes that manage the lifetime
| of a single SEXP -- ie, what Rcpp does with its classes.
| 
| You might consider just using e.g. std::unordered_map<T, Rcpp::RObject> if
| you need to map some arbitrary types to R objects.

+1, or "what he said" which I generally have on auto-loop for Kevin anyway ...

Dirk

-- 
http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org


More information about the Rcpp-devel mailing list