4

I have googled this problem and looked in R extensions manual, but could find no information on it.

I have a reasonably large program which makes many calls to C code with .C. I am passing in quite a lot of data which doesn't change over the course of the program. I therefore decided to coerce them to the right datatype just once:

vec = as.integer(as.vector(vec)).

Then in the .C call I write:

.C('function', vec = vec)

as opposed to

.C('function', vec = as.integer(as.vector(vec))).

This was done as profiling revealed as.* was taking up a bit of time. However in doing this I get (after a few hundred thousand iterations) a glibc error in malloc:

* glibc detected /usr/lib/R/bin/exec/R: malloc(): memory corruption: 0x0cabc0d8 **

I am just curious as to why this happens, seeing as the object I coerced at the start does not change over the course of the program, and if there is a way to get around this so I can minimise my as.* calls.

Thanks,

Chris

4

1 回答 1

0

你很可能只是在你的 C 函数中有一个错误,或者你试图释放你作为参数得到的整数向量,这是你不应该的。无论如何,这一定与您预先转换矢量的事实无关。

你如何为你的函数提供向量的长度?

于 2013-07-03T09:15:50.593 回答