RStudio crashes *after* calling an Rcpp function multiple times

微笑、不失礼 提交于 2019-12-01 11:54:15

问题


I've written some Rcpp code to find intersections in two piecewise linear curves. I approached the problems in the naive way requiring nested loops (checking all pairs of segments), so went to Rcpp for speed. (The problem is pictorially described in "Example 1" here: https://prezi.com/rwkji_leuwdr/r-and-c-integration/ )

The code compiles fine with sourceCpp, and even runs fine and gives expected results. BUT, the strange issue is that it consistently crashes RStudio either after running it multiple times (say, 5 or 6), or a little while after running it. I haven't seen anyone else document this sort of problem in a google/stack overflow search. I'm new to C++ and don't have any kind of intuition as to where the problem is coming from; seems like pretty weird behavior to me given that the functions run as desired at first.

Code and data are here: https://github.com/suztolwinskiward/ReproducepRoblem

Thanks in advance to anyone who helps!


回答1:


FWIW, I had the same problem and the bug seemed to be that I was trying to allocate too much data to a vector. It might be helpful to use the () operator rather than the [] operator in Rcpp. With [] my code would compile and crash after I ran it a few times; with () the code will compile but it'll throw an error at runtime.



来源:https://stackoverflow.com/questions/33768796/rstudio-crashes-after-calling-an-rcpp-function-multiple-times

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!