[Rcpp-devel] freeing memory
rosterma at abo.fi
rosterma at abo.fi
Sat Mar 26 10:35:10 CET 2016
rinside_sample1 can only be invoked once, i.e. RInside R remains hanging
after returning form the function when invoking it as a function. How
can it be invoked multiple times, some way of freeing the instance of R
is needed? Simple delete R does not work.
On 24.3.2016 21:55, Dirk Eddelbuettel wrote:
>
> Hi there,
>
> On 24 March 2016 at 21:37, rosterma at abo.fi wrote:
> | I have used the example rinside_sample1.cpp as a basis for a short
> | routine to transmit data from C++ to R and to recover the results from R
> | to C++. On the face of it, everything works nicely both in our mainframe
> | (linux) computer at ÅAU and on the supercomputers at CSC IT Center of
> | Science (Helsinki). Before proceeding - not being an R expert myself - I
> | wanted to check the memory absorbance of the system. When checking the
> | program flow with Valgrind, the debugger signals that several blocks of
> | data are still reachable when exiting. This cannot be,
> | since multiple calls to the routine would quickly absorb the CPU.
>
> valgrind is a very powerful tool. But when you embed R, which is an
> interpreted language with its own memory pool and management, you have to
> expect a few differences.
>
> Often, when I encounter such an example I try to first form a
> baseline. Something like creating a C++ executable instantiating RInside, and
> then 'doing nothing'. Maybe Sys.sleep(5) or something like that. Run it
> under valgrid, not how is want /may be/ unreachable or not freed /when you
> have not actually allocated anything/.
>
> Then do the same, but create a matrix or vector with, say, 10e3, then 10e4,
> then 10e5, ... elements and look at the output.
>
> | So, how do I free memory for example when allocating it through commands
> | such as:
> | Rcpp::NumericMatrix C_R=createMatrix(CATSM_INFO[0],cm,cn);
> | Rcpp::NumericVector v = R.parseEval(str);
> | string result(argv[1]);
>
> The nice thing about C++ is that it has constructors and destructors so /a
> priori/ you should not need to do anything.
>
> | How should the example rinside_sample1.cpp be modified to get this
> | straight and to avoid the risk of excessive memory absorbance in
> | multiple calls?
>
> Not to sound flippant, but we first need to really demonstrate that there
> actually is a leak.
>
> Hope this helps, Dirk
>
--
Ralf Östermark
Ph.D(econ), Ph.D(pol)
Professor of Accounting and Optimization Systems
School of Business Economics at
Åbo Akademi University
20500 Åbo
Finland
More information about the Rcpp-devel
mailing list