[Rcpp-devel] How to free memory in Rcpp

Dirk Eddelbuettel edd at debian.org
Fri Dec 14 04:06:58 CET 2012


Honglang,

You are now abusing the free facilities offered by this list.  Your examples
are not self-contained [ no sample data or simulated data ] and hence not
reproducible.  Your code is complex, and not motivated. And we have told you
REPEATEDLY to shorten your code to chunks until it works.

On 13 December 2012 at 21:15, Honglang Wang wrote:
| I have no idea what's this error. 

My best guess is that we already explained this to you, but you are not
really reading our replies all that closely.  Here is a hint: repeatedly
calling an R function is probably not the smartest thing to do in an
otherwise complex and hard to decipher program. [1]

| I am just wondering whether I need to free some memory in this code.

You are also making it pretty clear that you don't really know what you are
doing with C++, or else you would not ask this question (and the earlier
email people were to polite to reply to).

I suggest that you take a deep breath, go for a walk and once you're back,
start learning about C++.

So please stop emailing the list unless you have something more substantial
to post or ask -- and follow common courtesy and list etiquette. 

Right now you are wasting your time, as well as the time of a few hundred
list subscribers.  Stop now.

Dirk


[1] Just to be plain: Calling a function repeatedly is not per se a bad
thing.  Complete example below.

-----------------------------------------------------------------------------
#include <Rcpp.h>

using namespace Rcpp;

// [[Rcpp::export]]
double foo(Function f, NumericVector x) {
  double r = 0.0;
  for (int i=0; i<100; i++)
    r += as<double>(f(x));
  return r;
}


/*** R
x <- 1:10
foo(mean, x)
***/
-----------------------------------------------------------------------------

Here is the result from the 100 calls:

R> sourceCpp("/tmp/fun.cpp")

R> x <- 1:10

R> foo(mean, x)
[1] 550
R> 


As expected...




-- 
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com  


More information about the Rcpp-devel mailing list