Displaying 1 result from an estimated 1 matches for "rindex_open".
2007 Aug 03
2
How to properly finalize external pointers?
...n directly as a parameter)
Best regards
Jens Oehlschl?gel
// C-code
static void rindex_finalize(SEXP extPtr){
pINT ptr = R_ExternalPtrAddr(extPtr);
if(ptr){
Free(ptr);
Rprintf("finalized\n");
}else{
Rprintf("nothing to finalize\n");
}
return;
}
SEXP rindex_open(
SEXP Sn
){
int i,n = INTEGER(Sn)[0];
pINT ptr = Calloc(sizeof(INT)*n, INT);
SEXP extPtr, ret;
for (i=0;i<n;i++){
ptr[i] = i;
}
extPtr = R_MakeExternalPtr(ptr, install("Rindex_extPtr"), R_NilValue);
R_RegisterCFinalizer(extPtr, rindex_finalize);
PROTECT(ret = all...