[Rd] R_alloc with more than 2GB (PR#7721)

From: <huber_at_ebi.ac.uk>
Date: Thu 10 Mar 2005 - 21:07:08 GMT


Full_Name: Wolfgang Huber
Version: R-devel_2005-03-10
OS: alphaev68-dec-osf4.0f
Submission from: (NULL) (62.253.128.15)

This report concerns allocation of large (>2^31 byte) chunks of memory with R_alloc. I suspect it is a bug/typo but please don't hate me if it's actually a feature:

In R, I can happily create large matrices:

> a= matrix(0, nrow=191481, ncol=3063)
> dim(a)
[1] 191481 3063
> length(a)*8 / 2^30
[1] 4.369812

but when I call R_alloc in some of my C code, I get "negative length vectors are not allowed":

    maxcp = 3063; n = 191481;
    vs = (long) maxcp * (long) n;
    mI = (double*) R_alloc(vs, sizeof(double));

I suspect this caused by allocString(int), which is called by R_alloc, see below. Would it be possible to have allocString take a long argument as well?

These code excerpts are from R-devel_2005-03-10.tar.gz:

char *R_alloc(long nelem, int eltsize) {  R_size_t size = nelem * eltsize;
 SEXP s = allocString(size);
 ...
}

SEXP allocString(int length) {

   return allocVector(CHARSXP, length);
}

SEXP allocVector(SEXPTYPE type, R_len_t length) { ...

   case CHARSXP:

        size = BYTE2VEC(length + 1);
...

   malloc(sizeof(SEXPREC_ALIGN) + size * sizeof(VECREC))) ...
}



R-devel@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Fri Mar 11 13:55:57 2005

This archive was generated by hypermail 2.1.8 : Mon 20 Feb 2006 - 03:21:01 GMT