Skip to content
Prev 24391 / 63424 Next

Suggestion for memory optimization and as.double() with friends

Prof Brian Ripley <ripley at stats.ox.ac.uk> writes:
Hmm, this does not appear to avoid the copy for me.  Using R 2.5.0
alpha r40916 I get:

    > x <- 1:10 * 2.3
    > names(x)=LETTERS[1:10]
    > storage.mode(x)
    [1] "double"
    > tracemem(x)
    [1] "<0x2a7f008>"
    > storage.mode(x) <- "double"
    tracemem[0x2a7f008 -> 0x1fa6df8]: 

Note that actually changing the storage results in a surprising amount
of copying:

    > storage.mode(x) <- "integer"
    tracemem[0x1fa6df8 -> 0x1fa6d60]: 
    tracemem[0x1fa6d60 -> 0x1fa6808]: as.integer.default as.integer eval eval storage.mode<- 
    tracemem[0x1fa6808 -> 0x2c26b18]: as.integer.default as.integer eval eval storage.mode<- 
    tracemem[0x2c26b18 -> 0x2c26a88]: storage.mode<- 


+ seth
Message-ID: <m21wj8ksht.fsf@ziti.fhcrc.org>
In-Reply-To: <Pine.LNX.4.64.0703290256240.6919@gannet.stats.ox.ac.uk> (Brian Ripley's message of "Thu, 29 Mar 2007 03:11:18 +0100 (BST)")