comp.lang.ada
 help / color / mirror / Atom feed
* Value and reference, efficiency
@ 1996-08-28  0:00 Richard Irvine
  0 siblings, 0 replies; only message in thread
From: Richard Irvine @ 1996-08-28  0:00 UTC (permalink / raw)



In Smalltalk (as far as I understand) objects maniplated in programs 
are in fact pointers. For example the result of

   anObject := anotherObject.

is to have two pointers to the same piece of storage.

One has to be aware of this because if one goes on to
perform an operation which updates either of the 
objects it will appear to have updated both of them.
(If this is not what is required one can do

   anObject := anotherObject deepCopy.  

in this case new storage is acquired, the data
is physically copied and anObject points to the
new storage.)

In Ada, if the objects are records then

   anObject := anotherObject;

will result in a copy of the data being
made, so that subsequently updating one
object will have no effect on the other.

On the face of it one might expect that copying
of references would be more efficient than copying
of data.

In Ada one could replicate the Smalltalk way of
doing things and have objects which are in fact
pointers to dynamically acquired storage
and then just copy the pointer values on assignment.
(Now that controlled types are available one
could deallocate the storage automatically by
counting references.) 

What I wonder is whether there is any significant
performance advantage to be gained from doing this?




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1996-08-28  0:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-08-28  0:00 Value and reference, efficiency Richard Irvine

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox