[Rcpp-devel] How to free memory in Rcpp

Honglang Wang wanghonglang2008 at gmail.com
Fri Dec 14 04:25:15 CET 2012


I am sorry that I was abusing this list. My point is
1) First, this code works for me for some simulation cases. I repeated the
simulation 1000 times, which then called this Rcpp function 1000 times at
least. And this code worked perfectly.
2) But in some other simulation case (here what I mean by simulation case,
just change some parameters to produce the data, but the data formats are
the same.), when I repeated the simulation 1000 times, at some point, for
example, at the 298th simulation, it did not work. Then in order to see
what is the problem, I just did the 298th simulation separately (since I
set the seed, it used the same data), but it worked well in this case. Then
I really have no idea what is going on there.

Best wishes!

Honglang Wang

Office C402 Wells Hall
Department of Statistics and Probability
Michigan State University
1579 I Spartan Village, East Lansing, MI 48823
wangho16 at msu.edu



On Thu, Dec 13, 2012 at 10:06 PM, Dirk Eddelbuettel <edd at debian.org> wrote:

>
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20121213/2a97ceb3/attachment.html>


More information about the Rcpp-devel mailing list