search for: rindex_close

Displaying 1 result from an estimated 1 matches for "rindex_close".

2007 Aug 03
2
How to properly finalize external pointers?
...xtPtr, 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 = allocVector(VECSXP, 1)); SET_VECTOR_ELT(ret,0,extPtr); UNPROTECT(1); return ret; } SEXP rindex_close( SEXP obj ){ int i, n= 10; SEXP ret, extPtr=VECTOR_ELT(obj, 0); pINT p, ptr = R_ExternalPtrAddr(extPtr); PROTECT(ret = allocVector(INTSXP, n)); p = INTEGER(ret); for (i=0;i<n;i++){ Rprintf("ptri=%d\n",ptr[i]); p[i] = ptr[i]; } /* this does finalize immediate...