diff R/rdyncall/demo/R_malloc.R @ 0:0cfcc391201f

initial from svn dyncall-1745
author Daniel Adler
date Thu, 19 Mar 2015 22:26:28 +0100
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/R/rdyncall/demo/R_malloc.R	Thu Mar 19 22:26:28 2015 +0100
@@ -0,0 +1,16 @@
+# Package: rdyncall 
+# File: demo/R_malloc.R
+# Description: using R's memory allocator directly in R
+
+dynbind("R","R_chk_calloc(ii)p;R_chk_free(p)v;")
+malloc <- function(size) 
+{
+  x <- R_chk_calloc(as.integer(size),1L)
+  reg.finalizer(x, R_chk_free)
+  return(x)
+}
+
+x <- malloc(1024)
+x <- NULL
+gc()
+