metrumresearchgroup / mrgsolve

Simulate from ODE-based population PK/PD and QSP models in R
https://mrgsolve.org
GNU General Public License v2.0
131 stars 36 forks source link

Save function pointers in model object #1232

Open kylebaron opened 2 months ago

kylebaron commented 2 months ago

I think rather than making it work like this by default, instead let the user cache the pointers for when the model is getting run over and over.

  1. Helper functions to setpointers() and getpointers()
  2. Put C++ code in mrgsolve.cpp
  3. Put function in mrgsolve_init.cpp
  4. Optional refresh
  5. Modify loadso()
  6. Modify mread()
  7. Modify mread_cache()
// [[Rcpp::export]]
bool VALIDPOINTERS(Rcpp::List x) {
  if(x.size()==0) return false;
  for(size_t i = 0; i < x.size(); ++i) {
    if(R_ExternalPtrAddr(x[i]) == NULL) {
      return false;  
    }
  }
  return true;
}
setpointers <- function(x) {
  x@shlib$pointers <- pointers(x, refresh = TRUE)
  x
}

getpointers <- function(x) {
  x@shlib$pointers  
}