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

Seth Falcon sfalcon at fhcrc.org
Thu Mar 29 16:57:02 CEST 2007


Prof Brian Ripley <ripley at stats.ox.ac.uk> writes:
> The usual 'trick' to avoid this copy is
>
> storage.mode(x) <- "double"

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

-- 
Seth Falcon | Computational Biology | Fred Hutchinson Cancer Research Center
http://bioconductor.org



More information about the R-devel mailing list