[Rcpp-devel] Logic error causes R memory to be corrupt

Anton Bossenbroek anton.bossenbroek at me.com
Thu Oct 6 19:41:03 CEST 2016


> On 6 Oct 2016, at 13:36, Dirk Eddelbuettel <edd at debian.org> wrote:
> 
> 
> On 6 October 2016 at 13:12, Anton Bossenbroek wrote:
> | The idea behind my code is that I want to create a C++ backend to the
> | GeneralTree package I recently committed on CRAN (https://cran.r-project.org/
> | web/packages/GeneralTree/index.html ). I have two goals:
> | 1. provide a fast and unified interface to xml, JSON, YAML parsers. 
> | 2. provide a easy way to handle different models based on the same data using
> | decision rules in the tree
> | 
> | The reason I want to write the backend in C++ is because R6 objects are slow. I
> | initially wanted to keep objects by reference to prevent data.frames or entire
> | models to be copied, which could be more important in case 2 than 1. What is
> | your thought on this?
> 
> Everything you get from R is already by reference (well, technically, a
> pointer as the P in SEXP). That is the beauty of proxy objects in Rcpp.
> 
That’s what I thought, but also the reason why I don’t understand why the memory becomes corrupt with large n.

> So just simplify things, and don't interfere with R's memory management.
> Should be much smoother sailing.
> 
With my ignorance of Rcpp, say I where to implement this in C++ I would make the content either with void *. Templates wouldn’t work since the type of data is only known at runtime. Would this solve part of the problem?

> I get the feeling that are both very ambitious, yet somewhat new to Rcpp. I
> would simply urge patience, recommend you study a couple of existing packages
> and start small.
> 
I guess you a right, it’s the first time for me writing a data structure in C++ for R. I used Rcpp more for optimization of inner loops, never data structures.

> Good luck,  Dirk
> 
> -- 
> http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org



More information about the Rcpp-devel mailing list