Hi All, I am in the process of writing an R extension in c++ and am using several STL containers (e.g., vector<double>, map<int, double>, multimap<int, double>). I make sure to clear all these containers at the end of the .Call. Everything compiles and runs just fine, but I'm a bit worried since I haven't found any other packages that use STL. So, my question: is it OK to use the STL containers in my code? Will the use of this library somehow limit portability of this package? Or cause memory management problems? Thanks- Andy Andrew Finley, Research Fellow Department of Forest Resources College of Natural Resources University of Minnesota 305 Green Hall 1530 Cleveland Avenue N. St. Paul, MN 55108 Ph 612-624-1714 office http://blue.fr.umn.edu/home www.cnr.umn.edu/FR/people/facstaff/finley/index.html
Using C++ will reduce portability of your code. Using C++'s STL (not R's stl, so it is a good idea to spell out jargon) will reduce the portability further. R itself does not use C++, and although a C++ compiler is found, it is only very mininally tested (and in particular its headers and libraries are not checked). Some of us have only rather old C++ compilers on commercial Unixen. On Wed, 4 Jan 2006, Andrew Finley wrote:> Hi All, > I am in the process of writing an R extension in c++ and am using several > STL containers (e.g., vector<double>, map<int, double>, multimap<int, > double>). I make sure to clear all these containers at the end of the > .Call. Everything compiles and runs just fine, but I'm a bit worried > since I haven't found any other packages that use STL. > > So, my question: is it OK to use the STL containers in my code? Will the > use of this library somehow limit portability of this package? Or cause > memory management problems? > > Thanks- > Andy > > > Andrew Finley, Research Fellow > Department of Forest Resources > College of Natural Resources > University of Minnesota > 305 Green Hall > 1530 Cleveland Avenue N. > St. Paul, MN 55108 > > Ph 612-624-1714 office > http://blue.fr.umn.edu/home > www.cnr.umn.edu/FR/people/facstaff/finley/index.html > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel > >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Andrew Finley <finle014 <at> umn.edu> writes:> I am in the process of writing an R extension in c++ and am using several > STL containers (e.g., vector<double>, map<int, double>, multimap<int, > double>). I make sure to clear all these containers at the end of the > .Call. Everything compiles and runs just fine, but I'm a bit worried > since I haven't found any other packages that use STL.RQuantLib, a wrapper to the QuantLib libraries, has indirect exposure to Boost. [ QuantLib uses Boost smart pointers, and unit testing. ] However, I have kept the actual R-to-QuantLib interface very 'plain C' to keep it simple and sane. Dominick Samperi wrote a Rcpp.{hpp,cpp} class for C++ to R interface that is used in RQuantLib. Dominick was musing about releasing this stand-alone to CRAN as well, but I don't think it has happened.> So, my question: is it OK to use the STL containers in my code? Will theIn my book, yes. It would be nice to have a few nice, and documented, examples.> use of this library somehow limit portability of this package?I don't see why. Effectively, R goes where gcc/g++ go so if you make sure you stay within the bounds of g++. It will create an external dependency, as those do confuse users from time to time (c.f. the r-help archives).> Or cause memory management problems?If you have a bug, yes. If you don't, you don't. The R Extensions manual has a few tips on the matter. Cheers, Dirk