WARNING: This is very limited proof of concept!
# S3 method for class 'CFunc'
marshal(inline, ...)
# S3 method for class 'CFunc'
marshallable(...)
A marshalled
object as described in marshal()
.
Currently, it is only possible to marshal a function:
of class CFunc
that was created without "includes" or "otherdefs"
if (requireNamespace("inline", quietly = TRUE)) {
code <- "
int i;
for (i = 0; i < *n; i++) x[0] = x[0] + (i+1);
"
sum_1_to_n <- inline::cfunction(
signature(n = "integer", x = "numeric"),
code,
language = "C", convention = ".C"
)
## Marshal CFunc function
sum_1_to_n_ <- marshal(sum_1_to_n)
## Unarshal CFunc function
sum_1_to_n2 <- unmarshal(sum_1_to_n_)
y <- sum_1_to_n(10, 0)$x
print(y)
y2 <- sum_1_to_n2(10, 0)$x
print(y2)
}