Hi Yan,<br>Thanks a lot. Your advice is really the point for me. Have a good night.<br><br clear="all"><div><div>Best wishes!</div><div> </div><div>Honglang Wang</div><div> </div><div>Office C402 Wells Hall</div><div>Department of Statistics and Probability</div>
<div>Michigan State University</div><div>1579 I Spartan Village, East Lansing, MI 48823</div><div><a href="mailto:wangho16@msu.edu" target="_blank">wangho16@msu.edu</a></div></div><br>
<br><br><div class="gmail_quote">On Thu, Dec 13, 2012 at 10:54 PM, Yan Zhou <span dir="ltr"><<a href="mailto:zhouyan@me.com" target="_blank">zhouyan@me.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word">You really are not reading the list as close as you should be. If you want advice, then take it when people give it to you or stop asking.<div><br></div><div>AFAIK, your code does not involve manually allocated memory, all memories are managed by RAII objects, I don't see where the question of "freeing memory" come from. And the error message suggests nothing about memory problems. So either you have no idea of C++ at all or you are just asking some random question and hope others to debug your code. The later is not going to happen.<br>
<div><br><div><div class="im"><div>On Dec 14, 2012, at 3:25 AM, Honglang Wang <<a href="mailto:wanghonglang2008@gmail.com" target="_blank">wanghonglang2008@gmail.com</a>> wrote:</div><br><blockquote type="cite">I am sorry that I was abusing this list. My point is <br>
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.<br></blockquote></div>Computers don't do random things, unlike human beings. Something worked once, is very likely to work whatever times you repeat it as long as the input is the same (unless the function has side effect). So repeating it 1000 times is the same as once.</div>
<div><div class="im"><br><blockquote type="cite">
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.<br>
</blockquote></div>Since you already find an input that crash the program, you should go through the function to see where exactly the crash happens. For example, print out the intermediate steps in both R and C++ side to see where the execution stopped. Using a debugger is better. Sometime it takes a great time to trace back the crash site. Debugging can be exhausting. But it is supposed to be done by YOU. You cannot throw a bunch of code to the list, ask a non-sense question, and hope others to spend time to debug it for you.</div>
<div><br></div><div>Here are a few things people usually do before asking in a mailing list (not just Rcpp list, any such lists like R-help, StackOverflow, etc).</div><div>1. I write a program, it crashes,</div><div>2. I find out the site of crash</div>
<div>3. I make the program simpler and simpler until it is minimal and the crash is now reproducible.</div><div>4. I still cannot figure out what is wrong with that four or five lines that crash the minimal example</div><div>
5. I ask</div><div><br></div><div>Ask yourself, have you go through the first 4 steps? It does not matter how stupid your questions are. We all asked silly questions before, that is how we learn. But it matters you put in effort to ask the right question. The more effort you put into it, the more specific question you ask and more helpful answers you get. I suspect you don't know how to do that at all.  So if I were you, I will take Dirk's advice, take a deep breath, go for a walk, and start learning C++.</div>
<div><br></div><div>Yan</div><div><br><blockquote type="cite"><br></blockquote><blockquote type="cite"><div><div class="h5"><div><div>Best wishes!</div><div> </div><div>Honglang Wang</div><div> </div><div>Office C402 Wells Hall</div>
<div>Department of Statistics and Probability</div><div>Michigan State University</div><div>1579 I Spartan Village, East Lansing, MI 48823</div>
<div><a href="mailto:wangho16@msu.edu" target="_blank">wangho16@msu.edu</a></div></div><br>
<br><br><div class="gmail_quote">On Thu, Dec 13, 2012 at 10:06 PM, Dirk Eddelbuettel <span dir="ltr"><<a href="mailto:edd@debian.org" target="_blank">edd@debian.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<br>
Honglang,<br>
<br>
You are now abusing the free facilities offered by this list.  Your examples<br>
are not self-contained [ no sample data or simulated data ] and hence not<br>
reproducible.  Your code is complex, and not motivated. And we have told you<br>
REPEATEDLY to shorten your code to chunks until it works.<br>
<div><br>
On 13 December 2012 at 21:15, Honglang Wang wrote:<br>
| I have no idea what's this error.<br>
<br>
</div>My best guess is that we already explained this to you, but you are not<br>
really reading our replies all that closely.  Here is a hint: repeatedly<br>
calling an R function is probably not the smartest thing to do in an<br>
otherwise complex and hard to decipher program. [1]<br>
<div><br>
| I am just wondering whether I need to free some memory in this code.<br>
<br>
</div>You are also making it pretty clear that you don't really know what you are<br>
doing with C++, or else you would not ask this question (and the earlier<br>
email people were to polite to reply to).<br>
<br>
I suggest that you take a deep breath, go for a walk and once you're back,<br>
start learning about C++.<br>
<br>
So please stop emailing the list unless you have something more substantial<br>
to post or ask -- and follow common courtesy and list etiquette.<br>
<br>
Right now you are wasting your time, as well as the time of a few hundred<br>
list subscribers.  Stop now.<br>
<br>
Dirk<br>
<br>
<br>
[1] Just to be plain: Calling a function repeatedly is not per se a bad<br>
thing.  Complete example below.<br>
<br>
-----------------------------------------------------------------------------<br>
#include <Rcpp.h><br>
<br>
using namespace Rcpp;<br>
<br>
// [[Rcpp::export]]<br>
double foo(Function f, NumericVector x) {<br>
  double r = 0.0;<br>
  for (int i=0; i<100; i++)<br>
    r += as<double>(f(x));<br>
  return r;<br>
}<br>
<br>
<br>
/*** R<br>
x <- 1:10<br>
foo(mean, x)<br>
***/<br>
-----------------------------------------------------------------------------<br>
<br>
Here is the result from the 100 calls:<br>
<br>
R> sourceCpp("/tmp/fun.cpp")<br>
<br>
R> x <- 1:10<br>
<br>
R> foo(mean, x)<br>
[1] 550<br>
R><br>
<br>
<br>
As expected...<br>
<span><font color="#888888"><br>
<br>
<br>
<br>
--<br>
Dirk Eddelbuettel | <a href="mailto:edd@debian.org" target="_blank">edd@debian.org</a> | <a href="http://dirk.eddelbuettel.com/" target="_blank">http://dirk.eddelbuettel.com</a><br>
</font></span></blockquote></div><br></div></div><div class="im">
_______________________________________________<br>Rcpp-devel mailing list<br><a href="mailto:Rcpp-devel@lists.r-forge.r-project.org" target="_blank">Rcpp-devel@lists.r-forge.r-project.org</a><br><a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a></div>
</blockquote></div><br></div></div></div></blockquote></div><br>