Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reference classes not inhibiting copy #1

Open
bwlewis opened this issue Jun 2, 2014 · 0 comments
Open

Reference classes not inhibiting copy #1

bwlewis opened this issue Jun 2, 2014 · 0 comments

Comments

@bwlewis
Copy link
Collaborator

bwlewis commented Jun 2, 2014

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant