From toth.denes at ttk.mta.hu  Mon Jun  2 18:31:52 2014
From: toth.denes at ttk.mta.hu (=?ISO-8859-1?Q?D=E9nes_T=F3th?=)
Date: Mon, 02 Jun 2014 18:31:52 +0200
Subject: [Rd] memory allocation if multiple names point to the same object
In-Reply-To: <5377F03E.2020702@oracle.com>
References: <53779F9A.1040809@oracle.com>	<414982A9-728F-4018-9D96-C3005B57BC05@gmail.com>
	<5377F03E.2020702@oracle.com>
Message-ID: <538CA6F8.5060006@ttk.mta.hu>


Hi,

Please consider the following code:

a <- seq.int(10)  # create a
tracemem(a)
a[1:4] <- 4:1   # no internal copy
b <- a          # no internal copy
b[1:4] <- 1:4   # copy, b is not a any more
a[1:4] <- 1:4   # copy, but why?

With results:
 > a <- seq.int(10)
 > tracemem(a)
[1] "<0x1792bc0>"
 > a[1:4] <- 4:1
 > b <- a
 > b[1:4] <- 1:4
tracemem[0x1792bc0 -> 0x1792b58]:
 > a[1:4] <- 1:4
tracemem[0x1792bc0 -> 0x1792af0]:


##

Could you provide a brief explanation or point me to a source why R 
needs a copy in the final step?


Best,
   Denes



 > sessionInfo()
R version 3.1.0 (2014-04-10)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
  [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base



[Rd] memory allocation if multiple names point to the same object
=?ISO-8859-1?Q?D=E9nes_T=F3th?=