On 15.09.2018 00:05, Simon Woodward wrote: > My simulation model will be 1000+ lines of C++, this is a prototype, I > embedded the code inline to make it easier to post as a reprex to this forum.
A C++ file with a special /*** R ... */ comment would still be a minimal example. Just look at the code RStudio produces by default when you create a new C++ file. When you use Rcpp::sourceCpp() on that file, not only the code is compiled and linked, but the R code within this special comment is executed. RStudio does that by default when you source the file, e.g. via C-S-Return. > - do I need to worry about destructing my global variable my_spring (the > instance of my class)? If so, how do I do this? Global variables get destructed when the program ends. I would get rid the global variable, making it local to the translation unit. One way to achieve that would be an anonymous namespace. > - for read/write efficiency, can/should I make a persistent link > (Rccp::XPtr?) between the my_spring.variable property and an object or > function in R? If so, how do I do this? Or is it better simply to copy-pass > the data when needed and let Rccp handle the conversion from > std::unordered_map<string,double> to an R named vector? I am not sure what you are trying to do here. But as a general rule: try to write correct and working code first and do any performance optimizations when you know where the bottlenecks are. cheerio ralf -- Ralf Stubner Senior Software Engineer / Trainer daqana GmbH Dortustraße 48 14467 Potsdam T: +49 331 23 61 93 11 F: +49 331 23 61 93 90 M: +49 162 20 91 196 Mail: [email protected] Sitz: Potsdam Register: AG Potsdam HRB 27966 P Ust.-IdNr.: DE300072622 Geschäftsführer: Prof. Dr. Dr. Karl-Kuno Kunze _______________________________________________ Rcpp-devel mailing list [email protected] https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
