alloc | R Documentation |
This function and its methods dynamically allocate
memory (using the C routine calloc).
This allocates the appropriate number of bytes to accomodate
the specified type.
By default, the function arranges to garbage collect the
allocated memory when it is no longer referenced by an
R object. This may be undesirable as the memory may
still be in use by C code. In this case, one
can avoid garbage collection by specifying
FALSE
or NULL
for the finalizer
argument.
alloc(nbytes, finalizer = getNativeSymbolInfo("R_free")$address, ...)
nbytes |
the number of bytes to allocate or the
|
finalizer |
a logical, NativeSymbolInfo, NativeSymbol or character string
that indicates which the C routine as a symbol
to use to free the memory once it is no longer referenced
in R. A logical value of |
... |
additional parameters for methods, e.g. the class or instance of an R type to coerce the newly created pointer to. |
An external pointer object.
Duncan Temple Lang
addFinalizer
free
ptr = alloc(10)
gc()
rm(ptr)
gc()
i = alloc(sint32Type)
callCIF(CIF(voidType, pointerType), "fillInt", i, returnInputs = FALSE)
getNativeValue(i, sint32Type)
# these are somewhat dangerous.
# They rely on the externalptr being a pointer to a 32-bit int.
setAs("externalptr", "integer",
function(from)
getNativeValue(from, sint32Type))
setAs("RCReference", "integer",
function(from)
getNativeValue(from, sint32Type))
as(i, "integer")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.