【问题标题】:Using RInside destructor使用 RInside 析构函数
【发布时间】:2012-09-03 21:41:28
【问题描述】:

一个简单的实验表明,每个线程一次只允许一个 RInside 实例。

#include <RInside.h>

int main() {
  RInside R1;
  R1.parseEval("cat('Hello, R1\n')");
  RInside R2;
  R2.parseEval("cat('Hello, R2\n')");
  return 0;
}

程序崩溃,输出如下:

Hello, R1
terminate called after throwing an instance of 'std::runtime_error'
what():  can only have one RInside instance

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

但是,另一个连续创建 RInside 实例的实验的结果还不是很清楚。

#include <RInside.h>

int main() {
  RInside *R1 = new RInside();
  R1->parseEval("cat('Hello, R1\n')");
  delete R1;
  RInside *R2 = new RInside();
  R2->parseEval("cat('Hello, R2\n')");
  delete R2;
  return 0;
}

该程序在创建 R2 时会发出嗡嗡声。之前的输出如下所示:

Hello, R1
Lost warning messages

R1 析构函数调用不足以进行正确的 RInside 清理吗?

【问题讨论】:

    标签: r rcpp rinside


    【解决方案1】:

    ——刚才在 rcpp-devel 邮件列表and here is a link to the entire (short) thread 上讨论了这些。简而言之,它不是 RInside 析构函数,而是R API 本身,RInside 只是通过更易于使用的C++ 包装提供的。

    A follow-up post has been sent to r-devel as well 并在该线程中 Simon 明确指出,由于 R 本身存在许多静态全局变量,因此不太可能修复。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-03
      • 2011-04-16
      • 1970-01-01
      • 2016-01-29
      • 2014-11-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多