Comments (11)
Rcpp Modules register a default finalizer that calls the object's destructor. You can also add a custom finalizer if needed.
Sorry, I didn't catch that before. My rationale, originally, was that a custom finalizer would run upon gc() but the class destructor may be less predictable. If the above is correct, and the destructor does the necessary clean-up, then a custom finalizer may not be needed. Makes sense.
It seems to work fine either way for class VSIFile, and the destructor is called during garbage collection when not using .finalizer. I'll omit the custom finalizer in this case.
from rcpp.
Intended to circle back and let you know it is on CRAN but got distracted by a couple of things. My issue is resolved, but by not using the custom finalizer. The object's destructor is called at gc(), since Rcpp Modules registers a default finalizer as noted above (but I missed that previously). That meets my need and the cleanup code is very simple. The compiler warning appears though, if a custom .finalizer is defined on the exposed class, in case that's of interest. Thanks again.
from rcpp.
Good question. Modules has not seen a lot of love those last few years.
If your repo with added finalizer public? Not sure we have (m)any other examples of finalizers in use (though I have not looked yet).
from rcpp.
I think you're right; the class has virtual methods but no virtual destructor:
Rcpp/inst/include/Rcpp/Module.h
Lines 299 to 304 in 03fd09a
We should probably add it, or just simplify and remove the virtual inheritance used here (since FunctionFinalizer is the only thing that inherits from CppFinalizer)
from rcpp.
What do you think about e.g. rule of four adding the missing ones as defaults? (I am spitballing here...)
from rcpp.
Thanks for the quick response.
If your repo with added finalizer public?
It's currently in a branch of my fork here, but will be merged sometime soon.
https://github.com/ctoney/gdalraster/blob/vsifile/src/vsifile.h
https://github.com/ctoney/gdalraster/blob/vsifile/src/vsifile.cpp
I have a couple of other exposed classes that I would add finalizers for, but didn't have it working in the past so spending a little more time to check it out now.
Modules has not seen a lot of love those last few years.
FWIW, I really like modules and RCPP_EXPOSED_CLASS
. Super useful and nice to work with. Thanks!
from rcpp.
Do you want to give modifying the set of defaults and see where it leads you?
from rcpp.
update to the above, the class with finalizer has been merged in main:
https://github.com/USDAForestService/gdalraster/blob/main/src/vsifile.h
https://github.com/USDAForestService/gdalraster/blob/main/src/vsifile.cpp
from rcpp.
That's actually a pretty nice example for modules use!
from rcpp.
It's a nice API to be able to wrap and use from R. Class VSIFile
is in pretty good shape now I think, and has a decent set of tests for /vsimem/
at least. There is also a set of Rcpp exported functions for file system operations through GDAL VSI. Among other things, these fully abstract file system operations for cloud storage services.
https://usdaforestservice.github.io/gdalraster/reference/index.html#virtual-file-systems
And as side note, VSIFile
was initial use of RcppInt64 for this package. It made that part easy too. I was glad to add it and start using for int64 in a few other places as well.
from rcpp.
Hey @ctoney just circling back and as you (per CRANberries) have a new version on CRAN: are you all good here? What if any action items do we have left?
from rcpp.
Related Issues (20)
- Upstreaming `std::tuple<>` support HOT 10
- sourceCpp crashes R when called about 1000 times on same code HOT 10
- Integer overflow in `MatrixRow` offset calculations for large matrices HOT 8
- Switch from S4SXP to OBJSXP HOT 2
- pass by const refererence HOT 1
- A fresh -Wformat-security issue under r-devel HOT 9
- 'CRAN package Rcpp' notice HOT 5
- Installation/Compiling Error for Package with Rcpp dependency - Ubuntu (rvmf.cpp?) HOT 5
- Exporting classes using `Rcpp::interfaces(cpp)` that are shared among multiple cpp files through header file HOT 13
- test_packageversion fails with Rcpp 1.0.12 HOT 3
- Question regarding replacement by reference of <RTYPE>Array class without making copy HOT 8
- Cannot make std::vector<int8_t> from NumericVector HOT 4
- issue building phangorn 2.11 for wasm HOT 3
- New warnings from -Wconversion -Wno-sign-conversion HOT 13
- compileAttributes and use of .External2() for calling native symbol routine HOT 6
- Exporting comments into function definitions HOT 3
- `Rcpp:::LdFlags()` does not work correctly with R 4.4.0, pulling in warnings from `R` as if they were objects for the linker HOT 6
- New CRAN issues HOT 15
- Preparing for Rcpp 1.0.13 and asking four packages for an adjustment HOT 15
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rcpp.