Comments (4)
I don't think it is entirely trivial to do this. First as you mentioned we would need to use compatibility library so we could use it with C++11.
Second and perhaps more importantly cpp11 uses translateCharUT8()
to access character data from R vectors. This translates the characters to UTF-8 and (if needed) allocates memory that reclaimed at the end of the enclosing .Call()
. If we use string_view()
on this data and the string_view()
outlasts the .Call()
boundary the data will no longer be valid.
It might be that this particular case is rare enough and the benefits of string_view are substantial enough that it makes sense, I am not sure.
from cpp11.
Another pretty serious issue with using string_view
in cpp11 is that nearly all R APIs that have const char*
expect null terminated strings, which may not be the case with a string_view.
from cpp11.
Yeah the point about possible allocation by translateCharUTF8
totally makes sense. I guess I was thinking of string_view
as modeling the contents of a CHARSXP
"as it is". Operationally, I think of a string_view
as
- non-owning
- cheap to copy
- immutable (unlike other "data" SEXP, you can't muck easily around with the contents of a
CHARSXP
in-place because of theCHARSXP
cache.string_view
, unlike its cousinspan
, will only give you a const pointer to its contents) - "knowing" its own length
from cpp11.
Closing this issue for now, while I do think using string_view is a nice idea in theory, I don't think it really will work in practice for cpp11 due to the concerns expressed above.
from cpp11.
Related Issues (20)
- `package("<pkg>")` error if package namespace not found
- Release cpp11 0.4.4 HOT 4
- tests in 'tests/testthat.R' failed HOT 2
- Examples
- `unwind_protect()` global option is falsely assumed to be immutable HOT 1
- Nested `unwind_protect()` calls going through R can be very dangerous
- Release cpp11 0.4.6
- Issues with cpp11 0.4.4 changes to the preserve list structure
- std::max_element fails on writable vectors
- Writable vectors could allow `T&` conversion HOT 1
- Add `complexes` and `r_complex` support
- Memory leak with reassigning `cpp11::writable::list`, and maybe others HOT 1
- Importing more headers than required? [How to write a vector or integer's coordinates in R's cpp11?]
- Creating a growing `list` with cpp11 results in elements with `R_NilValue`s at one point HOT 1
- Release cpp11 0.4.7
- C++ ODR violated when using `testthat` HOT 2
- `SEXP` vs. `void *` HOT 1
- Error with list of vectors/matrices HOT 1
- `BEGIN_CPP11 + END_CPP11` -> using `Rf_errorcall(call, ...)` HOT 1
- Found non-API calls to R: `SETLENGTH`, `SET_TRUELENGTH` HOT 2
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 cpp11.