Had been looking into Luke Tierney's R_AllocatePtr() and was left with a question about exactly when does R reclaim heap memory. Implication of 'simpleref.nw' is that one can allocate C data on the R heap, and as long as pointer object is alive, the data and pointer will remain valid. But it calls allocString() which is implemented using R_alloc(). 'Writing R Extensions" says R will reclaim memory allocated using R_alloc() at the end of the .Call(). Was the intent that its invocation be restricted to within a .Call()? Doesn't sound as though it could be used to return an SEXP from a .Call() with its data intact. ---------------------------------------------------------- SIGSIG -- signature too long (core dumped)
On 7/19/05, Paul Roebuck <roebuck at odin.mdacc.tmc.edu> wrote:> Had been looking into Luke Tierney's R_AllocatePtr() and > was left with a question about exactly when does R reclaim > heap memory. Implication of 'simpleref.nw' is that one can > allocate C data on the R heap, and as long as pointer object > is alive, the data and pointer will remain valid. But it > calls allocString() which is implemented using R_alloc(). > > 'Writing R Extensions" says R will reclaim memory allocated > using R_alloc() at the end of the .Call(). > > Was the intent that its invocation be restricted to within > a .Call()? Doesn't sound as though it could be used to return > an SEXP from a .Call() with its data intact.Sounds like you may want an R external pointer object, which is also documented in simpleref.nw
On Tue, 19 Jul 2005, Paul Roebuck wrote:> Had been looking into Luke Tierney's R_AllocatePtr() and > was left with a question about exactly when does R reclaim > heap memory. Implication of 'simpleref.nw' is that one can > allocate C data on the R heap, and as long as pointer object > is alive, the data and pointer will remain valid. But it > calls allocString() which is implemented using R_alloc().Um, no. allocString is SEXP allocString(int length) { return allocVector(CHARSXP, length); } In fact the reverse is true, R_alloc is implemented using allocString. -thomas Thomas Lumley Assoc. Professor, Biostatistics tlumley at u.washington.edu University of Washington, Seattle