From sfalcon at fhcrc.org  Thu Mar 29 16:57:02 2007
From: sfalcon at fhcrc.org (Seth Falcon)
Date: Thu, 29 Mar 2007 07:57:02 -0700
Subject: [Rd] Suggestion for memory optimization and as.double() with
	friends
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)")
References: <59d7961d0703281425n161a100lf4fb36bcf95ac742@mail.gmail.com>
	<460AE657.9040402@stats.uwo.ca>
	<Pine.LNX.4.64.0703290256240.6919@gannet.stats.ox.ac.uk>
Message-ID: <m21wj8ksht.fsf@ziti.fhcrc.org>

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



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