【发布时间】:2015-06-06 19:43:36
【问题描述】:
allocVector() 函数有问题。我用 C 语言编写了一个可以在 R 中调用的代码 (DLL)。我想在 C# 中将该 DLL 的方法调用到我的应用程序中。 DLL 代码工作正常,但是当编译器到达下一行时 ROut = allocVector(INTSXP, 2*3) 它给出了以下异常: 未处理的异常:System.AccessViolationException:试图读取或写入受保护的内存。 代码如下:
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <R.h>
#include <Rinternals.h>
#include <Rmath.h>
#include <R_ext/Applic.h>
#include <R_ext/Lapack.h>
#include <Rdefines.h>
#ifdef __cplusplus
extern "C" {
#endif
void castType(int *result)
{
SEXP ROut;
ROut = allocVector(INTSXP, 2*3)
ROut = PROTECT(ROut);
int *clustOut = INTEGER(ROut);
result= clustOut ;
}
#ifdef __cplusplus
}
#endif
【问题讨论】: