[Rd] Question about SET_LENGTH
James Bullard
bullard at berkeley.edu
Mon Aug 29 20:15:28 CEST 2005
Hello all, thanks for all the help on the other issues. This one should
be relatively straightforward. I have a vector of integers which I
allocate to be the maximal size possible (meaning I'll never see more
than cel.GetNumOutliers, but most likely I'll see less) therefore, I
want to resize the vector, one solution would be to allocate a new
vector then to copy into the new vector. That is what I was going to do
until I saw the SET_LENGTH macro. Does this macro effectively take care
of the memory? Is this an acceptable use of the macro? The code works,
but I dont want any lurking memory problems.
PROTECT(outliers = NEW_INTEGER(cel.GetNumOutliers()));
if (i_readOutliers != 0) {
if (noutlier == 0) {
outliers = R_NilValue;
}
else if (noutlier < cel.GetNumOutliers()) {
SET_LENGTH(outliers, noutlier);
}
}
Thanks as always!
jim
More information about the R-devel
mailing list