inline (version 0.3.14)

utilities: printing, reading and writing CFunc objects

Description

writeDynLib saves the DLL and the CFunc or CFuncList object as generated by cfunction; readDynLib loads it.

The print and code methods respectively print the entire object or the code parts.

Usage

writeDynLib(x, file)
  readDynLib(file)

Arguments

x

A CFunc or CFuncList object as created by cfunction to be saved.

file

base name of the file to write the object to or to read from. Two files will be saved, one for the shared object or DLL (extension so or DLL) and one that holds the CFunc or CFuncList specification, without the function address (extension CFunc).

Value

Function readDynLib returns a CFunc or CFuncList object.

Methods

  • Method print(x, ...) prints the entire object x

signature(x = "CFunc")

Prints the CFunc object generated by cfunction, including the code that generated it.

signature(x = "CFuncList")

Print all CFunc objects generated by cfunction, including the code that generated them.

  • Method code(x, linenumbers = TRUE, ...) prints the code only

  • signature(x)

    The CFunc or CFuncList object as generated by cfunction.

    linenumbers

    If TRUE all code lines will be numbered.

    Details

    Both the CFunc or CFuncList object and the shared object or DLL are saved, in two files; the first has extension CFunc; the second so or DLL, depending on the operating system used.

    When reading, both files are loaded, and the compiled function address added to the object.

    See Also

    getDynLib

    Examples

    Run this code
    # NOT RUN {
    x <- as.numeric(1:10)
    n <- as.integer(10)
    
    code <- "
          integer i
          do 1 i=1, n(1)
        1 x(i) = x(i)**3
    "
    cubefn <- cfunction(signature(n="integer", x="numeric"), code, convention=".Fortran")
    code(cubefn)
    
    cubefn(n, x)$x
    
    # }
    # NOT RUN {
     fname <- tempfile()
     writeDynLib(cubefn, file = fname)
     # load and assign different name to object
     cfn <- readDynLib(fname)
     print(cfn)
     cfn(2, 1:2)
    # }
    # NOT RUN {
    # }
    

    Run the code above in your browser using DataLab