Dear all
I have written a function in C++ , equil_distC, that I am calling from an R script. In the last few days, R has repeatedly crashed when calling this function, or delivered obviously wrong outputs. However, when I restarted R after the crash, the results turned out to be OK most of the time although I had not modified the C++ code. Although the code runs correctly now, I am not sure why it does work right now, and didn't just an hour ago. Let me summarize the main steps I undertook: * After having modified the script with the C++ code, I compiled it using R CMD SHLIB mylatestversion.cpp - no problems occurred then. * Next, I loaded the dll into R with dyn.load("C:\\Ccodefortransortmodel\\ mylatestversion.dll") * Next, I called equil_distC with testres2 <- .C("equil_distC", as.integer(rowmaxfiets),as.integer(colmaxfiets), as.double(nodes), as.integer(links_dist_calc), as.integer(cyclepathsfirstline), as.integer(numzones), as.integer(numnodes), as.integer(numlinks), result = double(6)) * About half of the time, whenever I had changed the C++ code, the results were either nonsensical or R crashed. * When R did not crash, I unloaded the dll with: dyn.unload("C:\\Ccodefortransortmodel\\equildistCforodpair_2012_09_20v8.dll") * Next, I deleted the .dll and the .o of the most recent version, I modified the C++ code and I ran the above procedure again. * In most cases when R crashed, a new run of the procedure above resulted in correct results, even though the C++ code was not modified. I have also noticed that, in several cases, apparently irrelevant changes to the code would lead to a crash. This occurred for instance when I replaced %d with %f in Rprintf()) - my first conjecture was actually that this was the root of the problem, but the code runs correctly now with %f. My own conjecture is that, some way or another, old versions of equil_distC kept on circulating in memory. For instance, even after a dyn.unload of all previous versions of the dll, "is.loaded("equil_distC")" would still lead to a TRUE. I would like to understand the structural reason for these problems. Again, the problem is not the C++ code - it does run correctly now, although it had crashed in the previous run. Best regards Laurent Franckx, PhD VITO NV Boeretang 200, 2400 MOL, Belgium Tel. + 32 14 33 58 22 Skype: laurent.franckx laurent.fran...@vito.be ________________________________ [http://www.vito.be/e-maildisclaimer/bsds.png] <http://bsds.vito.be> VITO Disclaimer: http://www.vito.be/e-maildisclaimer ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.