Skip to content
Prev 33199 / 63424 Next

Memory management issues

If you are in control of the c++ library (i.e. it is not from a
vendor), then you can also override the new operator of your object so
that it allocates an SEXP.  if you implement PROTECT/UNPROTECT calls
correctly, then GC will not be a problem.

The approach that I've taken with my time series library is that you
specify a storage policy as a template parameter.  If you are using
regular c++, then vectors of double/int are just allocated normally in
c++, however, if you specify the R storage backend, then the
constructor allocates an SEXP of doubles and sets the object's pointer
to the first element in the vector.  The ojbect doesn't really know
that it's using R's backend storage.

Sources here:
R backend storage policy: http://github.com/armstrtw/r.tslib.backend/tree/master
tslib: http://github.com/armstrtw/tslib/tree/master

-Whit
On Sun, Jul 5, 2009 at 10:54 AM, Yuri D'Elia<wavexx at users.sf.net> wrote: