flexmem icon indicating copy to clipboard operation
flexmem copied to clipboard

Reference classes not inhibiting copy

Open bwlewis opened this issue 11 years ago • 0 comments

The ref doc states:

 "Pass an R object to ref. The return is an object that behaves like
 the original object but exhibits reference semantics. This class
 is useful when dealing with large objects and a user want to have
 control over when the object is copied."

But when I use ref, objects are still copied. Here is a test on R-3.02 on Ubuntu 12.04 (x86_64):

library("flexmem")
flexmem_threshold(1e6)
flexmem:::flexmem_memcpy_offset(40)
x = 1:1e6
Flexmem malloc address 0x7f76af998000, size 4000040, file  /tmp/fm_5WeDNO

y = ref(x)
Flexmem malloc address 0x7f76b0148000, size 4000040, file  /tmp/fm_7dVzXp
hash count = 2
CAZART! Flexmem memcopy address 0x7f76af998000 src_addr 0x7f76af998028 of size 4000040

addOne = function(x) x[] = x[] + 1

addOne(y)
Flexmem malloc address 0x7f76afd70000, size 4000040, file  /tmp/fm_NE4LSP
hash count = 3
CAZART! Flexmem memcopy address 0x7f76b0148000 src_addr 0x7f76b0148028 of size 4000040
Flexmem malloc address 0x7f76af1f0000, size 8000040, file  /tmp/fm_y255Pf
hash count = 4
Flexmem unmap address 0x7f76afd70000 of size 4000040
Flexmem ulink 0x7f76afd70000//tmp/fm_NE4LSP
Flexmem malloc address 0x7f76afd70000, size 4000040, file  /tmp/fm_Mgq8PF
hash count = 4
CAZART! Flexmem memcopy address 0x7f76b0148000 src_addr 0x7f76b0148028 of size 4000040
Flexmem malloc address 0x7f76aee18000, size 4000040, file  /tmp/fm_DL5eR5
hash count = 5
Flexmem malloc address 0x7f76ae670000, size 8000040, file  /tmp/fm_zFTQ0v
hash count = 6

It seems that two copies of the contents of y were made, not counting the initial copy from the vector x.

I don't think R5 is working as intended, at least not in this implementation.

bwlewis avatar Jun 02 '14 15:06 bwlewis