[Rcpp-devel] added raw support in RcppSexp
Romain François
francoisromain at free.fr
Tue Dec 22 12:15:02 CET 2009
On 12/22/2009 12:09 PM, Dirk Eddelbuettel wrote:
>
> On 22 December 2009 at 10:46, Romain François wrote:
> | Hi,
> |
> | I've just added raw vector support into the RcppSexp class, so it gains:
> |
> | RcppSexp(const Rbyte& v);
> | RcppSexp(const std::vector<Rbyte> & v);
> | std::vector<Rbyte> asStdVectorRaw() const;
> |
> | I've also added the appropriate examples in RcppSexpTests.r
>
> Neat, thanks, particularly
>
> +std::vector<Rbyte> RcppSexp::asStdVectorRaw() const {
> + int n = Rf_length(m_sexp);
> + std::vector<Rbyte> v(n);
> + switch( TYPEOF(m_sexp) ){
> + case RAWSXP:
> + {
> + v.assign( RAW(m_sexp), RAW(m_sexp)+n ) ;
> + break ;
> + }
>
> I've long wondered why/how/if we could assign more efficiently -- but STL
> Vectors don't let us just 'memcpy' a chunk.
I don't think you are guaranteed that the elements are contiguous, so I
would not go down there.
> Would this 'more iterator like' assign(a,b) work for the types INTEGER, REAL
> too?
yep. I derived this from reading item 5 of Effective STL, and how the
author is rambling about using range functions rather than looping around.
a and be can be int* which is what INTEGER(x) would give you.
> Dirk
>
--
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/HlX9 : new package : bibtex
|- http://tr.im/Gq7i : ohloh
`- http://tr.im/FtUu : new package : highlight
More information about the Rcpp-devel
mailing list