Calling .C () R function constantly with static vectors, do you need to continue to use data types?

I searched for this problem and looked through the manual of R-extensions, but could not find information about it.

I have a large enough program that makes a lot of C code calls with .C. I transmit quite a lot of data that does not change during the program. Therefore, I decided to force them to the correct data type only once:

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

Then in the .C call I write:

.C ('function', vec = vec)

Unlike

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

This was done as profiling, shown as. * took a little time. However, I get (after several hundred thousand iterations) a glibc error in malloc:

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

I’m just wondering why this happens, because the object that I forced to start does not change during the program, and if there is a way around this, I can minimize mine. * challenges.

Thanks,

Chris

+4
source share
1 answer

You probably have an error in your C function, or you are trying to free an integer vector that you received as an argument that you should not. In any case, this should not be due to the fact that you first convert your vector.

How do you pass the length of your vector into your function?

0
source

Source: https://habr.com/ru/post/1481063/


All Articles