0
|
1 # File: rdc/demo/malloc.R
|
|
2 # Description: sample demo to get malloc/free functions
|
|
3
|
|
4 if( .Platform$OS.type == "windows" ) {
|
|
5 .windir <- paste(Sys.getenv("windir")[[1]],"\\system32\\",sep="")
|
|
6 .libC <- paste(.windir,"msvcrt",sep="")
|
|
7 } else {
|
|
8 sysname <- Sys.info()[["sysname"]]
|
|
9 if (sysname == "Darwin")
|
|
10 {
|
|
11 .libC <- "/usr/lib/libc.dylib"
|
|
12 } else {
|
|
13 .libC <- "/lib/libc.so.6"
|
|
14 }
|
|
15 }
|
|
16
|
|
17 dyn.load(.libC)
|
|
18
|
|
19 bind <- function(name, signature)
|
|
20 {
|
|
21 address <- getNativeSymbolInfo(name)$address
|
|
22 assign(name, function(...) rdcCall(address,signature,...), parent.frame() )
|
|
23 }
|
|
24
|
|
25 bind("malloc","i)p")
|
|
26 bind("free","p)v")
|
|
27
|