[Rd] SEXPTYPEs

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri May 16 13:15:10 CEST 2014


On 16/05/2014 11:06, Duncan Murdoch wrote:
> On 16/05/2014, 4:16 AM, Adrian Dușa wrote:
>> Dear list,
>>
>> On a follow up from my previous email, I am now trying to allocate
>> vectors
>> of length larger than 32-bit in C.
>>
>>> From the R internals documentation, I read that:
>> "The sxpinfo header is defined as a 32-bit C structure..."
>> and
>> "A SEXPREC is a C structure containing the 32-bit header..."
>>
>> The question is: does the INTSXP allow vectors larger than 32-bit?
>>
>>
>> A test example:
>>
>> //###
>> int *p_temp;
>>
>> SEXP root = PROTECT(allocVector(VECSXP, 5));
>>
>> long long int verylargeinteger;
>> // something to compute verylargeinteger, > 32-bit
>>
>> SEXP temp = SET_VECTOR_ELT(root, 0, allocVector(INTSXP,
>> verylargeinteger));
>> p_temp = INTEGER(temp);
>> //###
>>
>> "temp" should be a vector of length > 32-bit, and "p_temp" should be the
>> pointer to that vector.
>>
>> If declaring:
>> long long int *p_temp;
>> (but the compiler throws a warning with an incompatible pointer type,
>> because pointers should be integers of course).
>>
>> I've looked at all SEXPTYPEs in the R internals, and the only one
>> specific
>> to integer vectors is INTSXP. Can this be used for vectors of length
>> larger
>> than 32-bit?
>
> Yes, see the section on "Long Vectors" in chapter 12.

('Yes on a 64-bit platform.')  The type for a vector length is R_xlen_t, 
e.g. allocVector is declared as

SEXP     Rf_allocVector(SEXPTYPE, R_xlen_t);

That is never 'long long int' ....

>
> Duncan Murdoch
>
>>
>> Thank you again, in advance,
>> Adrian
>>
>>
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel


-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-devel mailing list