From bullard at berkeley.edu  Mon Aug 29 20:15:28 2005
From: bullard at berkeley.edu (James Bullard)
Date: Mon, 29 Aug 2005 11:15:28 -0700
Subject: [Rd] Question about SET_LENGTH
Message-ID: <431350C0.8030804@berkeley.edu>

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



[Rd] Question about SET_LENGTH
James Bullard