Skip to content

reference to objects

2 messages · Giampiero Salvi, Thomas Lumley

#
Thanks for your answer,
The data should be read only (and all the objects share the same data values).
The problem with this solution is that I would like to use those objects with
already existing libraries, and thus I cannot choose how the data is read.
To explain better, I look for a way to reference to the data that is transparent
to the application.

In C this would be done by assigning the pointer to the data structure, for example
if dist is a C structure and obj1/2 contain a pointer called dist to that kind of
structure, I would do:

obj1->dist = &dist;
obj2->dist = &dist;

and then the rest of the code would not even know if obj1->dist is shared among different
objects....

Thanks again,
Giampiero
#
On Fri, 16 Jan 2004, Giampiero Salvi wrote (in reply to some unidentified
helper):
If the data are read only it is likely that R will *not* create two
copies, eg try
  a<-list(x=rnorm(1e6))
  gc()
  b<-a$x
  d<-a$x
  gc()
  b<-b+1
  d<-d+1
  gc()
This won't work any better.  get(obj1$data) will get the object, and
there's no reason to expect that it's less likely to get a copy than
simple assignment is.

	-thomas