Enables reference counting of objects allocated by R. It takes care of protecting and unprotecting objects from the R garbage collector.
R objects allocated inside R and passed to D are automatically protected. Attempting to protect/unprotect them will result in an error. R objects allocated by D have to be protected from the garbage collector while they are active, and unprotected when you are done with them.
This is an implementation of the reference counting scheme in Adam Ruppe's D Cookbook.
The Robj struct to be protected
The number of active references to ptr.
A flag indicating that the object needs to be unprotected when there are no more references to it. Set to false if working with data that was allocated in R and passed to D.