From dhinds at sonic.net  Sun Sep  4 07:42:17 2005
From: dhinds at sonic.net (dhinds@sonic.net)
Date: Sun, 4 Sep 2005 05:42:17 +0000 (UTC)
Subject: [Rd] A memory management question
Message-ID: <dfe1fp$buj$1@sea.gmane.org>

Can someone explain the use of SETLENGTH() and SETTRUELENGTH()?

I would like to allocate a vector and reserve some space at the end,
so that it appears shorter than the allocated size.  So that I can
more efficiently append to the vector, without requiring a new copy
every time. So I'd like to use SETLENGTH() with a shorter apparent
length, and bump this up as needed until I've used the entire space.

There are only a couple users of SETLENGTH() in R, and they all appear
at first glance to be pointless: a few routines use allocVector() and
then call SETLENGTH() to set the vector length to the value that was
just allocated.  What are valid uses for SETLENGTH()?  And what are
the intended semantics for "truelength" as opposed to the regular
length?

If GC happens and an object is moved, and its apparent LENGTH()
differs from its allocated length, does GC preserve the allocated
length, or the updated LENGTH()?  Is there any way to get at the
original allocated length, given an SEXP?

-- Dave



[Rd] A memory management question
dhinds@sonic.net