Skip to content

Instantly share code, notes, and snippets.

@jjallaire
Created February 17, 2015 22:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jjallaire/bfc84ce7dd566a0a7231 to your computer and use it in GitHub Desktop.
Save jjallaire/bfc84ce7dd566a0a7231 to your computer and use it in GitHub Desktop.
custom finalizer
#include <Rcpp.h>
using namespace Rcpp;
void finalizeInt(int* ptr) {
// do nothing
}
typedef XPtr<int,PreserveStorage,finalizeInt> XPtrInt;
// [[Rcpp::export]]
XPtrInt test() {
return XPtrInt(new int(10));
}
@dfeng
Copy link

dfeng commented Sep 21, 2016

Thanks for this! I've been trying to get custom finalizers working for the past hour, and the PreserveStorage was all I needed! I suspect you also need to have the true flag for set_delete_finalizer.

XPtr<Node, PreserveStorage, finalizeInt> ptr(new int(10), true);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment