[Rd] reducing a too-large matrix obtained with allocMatrix()

Steven Dirkse sdirkse at gams.com
Tue Nov 1 21:29:51 CET 2011


Hello,

I have some C code (for a shared lib called via .External)  that uses

PROTECT(w= allocMatrix(REALSXP, m, n));

mostly successfully.  In rare cases, though, the row count m will be
an overestimate.  Is there a way to reallocate the matrix in-place,
something like

reAllocMatrix (w,m-excess,n)    /* where excess is > 0 */

to chop off the last excess rows of w?  I only find out about the
excess rows during the single pass over the data made to copy it from
its source to w.

Short of this, all I know to do is allocate a matrix of the proper
size and copy the values.  Any other ways to do this?

-- 
Steve Dirkse



More information about the R-devel mailing list