多次调用 Rcpp 函数后,RStudio 崩溃* [英] RStudio crashes *after* calling an Rcpp function multiple times

查看:72
本文介绍了多次调用 Rcpp 函数后,RStudio 崩溃*的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一些 Rcpp 代码来查找两条分段线性曲线中的交点.我以需要嵌套循环(检查所有段对)的幼稚方式解决了这些问题,因此转到 Rcpp 以提高速度.(问题在此处的示例 1"中进行了图示:https://prezi.com/rwkji_leuwdr/r-and-c-integration/ )

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/ )

代码用 sourceCpp 编译得很好,甚至运行得很好并给出了预期的结果.但是,奇怪的问题是它在多次运行 RStudio 后(例如 5 或 6 次)或运行一段时间后始终崩溃.我还没有看到其他人在 google/stack overflow 搜索中记录过此类问题.我是 C++ 的新手,对问题的来源没有任何直觉;考虑到这些功能最初按需要运行,这对我来说似乎是很奇怪的行为.

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.

代码和数据在这里:https://github.com/suztolwinskiward/ReproducepRoblem

在此先感谢任何提供帮助的人!

Thanks in advance to anyone who helps!

推荐答案

FWIW,我遇到了同样的问题,错误似乎是我试图为向量分配太多数据.在 Rcpp 中使用 () 运算符而不是 [] 运算符可能会有所帮助.使用 [] 我的代码会在运行几次后编译并崩溃;使用 () 代码会编译,但会在运行时抛出错误.

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.

这篇关于多次调用 Rcpp 函数后,RStudio 崩溃*的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆