From vograno at evafunds.com  Wed Mar 16 19:34:56 2005
From: vograno at evafunds.com (Vadim Ogranovich)
Date: Wed Mar 16 19:35:18 2005
Subject: Write Barrier: was: [Rd] function-like macros undefined
Message-ID: <C698D707214E6F4AB39AB7096C3DE5A58FF45A@phost015.EVAFUNDS.intermedia.net>

Hi,

Thank you to Duncan Murdoch for pointing to
http://www.stat.uiowa.edu/~luke/R/barrier.html.
I have a couple of questions in this regard:

* suppose that inside a C function I have a SEXP vector x of integers
and I want to increment each element by one. I understand that

int * xIPtr = INTEGER(x);
int i;

for (i=0; i<LENGTH(x); ++i)
     SET_VECTOR_ELT(x, i, xIPtr[i]+1);


is the recommended way of doing it. However it seems that only the very
first call to SET_VECTOR_ELT, i.e. the one that corresponds to i=0, is
strictly necessary. For example, and this is my question, the following
should be perfectly safe:

SET_VECTOR_ELT(x, 0, xIPtr[0]);

for (i=0; i<LENGTH(x); ++i)
     ++xIPtr[i];


Admittedly this looks a bit odd and breaks if LENGTH(x) is zero, but it
illustrates the point.

* Now, if the above variation is safe, maybe there is a macro that
simply marks atomic SEXP-s, i.g. integers and doubles, for modification?

* The "Write Barrier" document has a section "Changing the
Representation of String Vectors". Is this something which is in works,
or planned, for future versions? It would be great if it were, this
should give R considerable speed boost.

Thanks,
Vadim


Write Barrier: was: [Rd] function-like macros undefined
Vadim Ogranovich