comp.lang.ada
 help / color / mirror / Atom feed
From: Mike Brenner <mikeb@mitre.org>
Subject: Re: Copying semantics molehill (was Re: True faiths)
Date: Tue, 22 Jan 2002 17:35:49 -0500
Date: 2002-01-22T17:35:49-05:00	[thread overview]
Message-ID: <mailman.1011738962.27774.comp.lang.ada@ada.eu.org> (raw)

> Can anyone show an example of a situation where copying semantics really matter?

In the semantics of the realtime world the most important attribute is speed, since nothing means anything if it does not arrive in time in that realtime world. Therefore, one example would be that unintentionally cloning something (duplicating all of its parts) might take up too many resources (time, memory, network bandwidth, etc.), and might therefore become meaningless, even though speed is not part of the equation in non-realtime semantics. In many situations, such as unchecked_conversions, there is a critical percentage difference between whether the compiler generates code to copy or whether it "does the copy at compile time". 


> Imagine you have an object with some simple attributes, and some connections to other complex objects, and you want to save this object to a file. A shallow copy would only take those attributes that were simple, for example, numbers and strings.

Perhaps it we could also define a shallow copy to also copy the top level of references to those complex objects?


> A deep copy would also copy out all of the connected complex objects,
and all of their connected objects, and all of their connected objects, etc.
For a great many objects that you will actually build,
a deep copy will eventually copy the entire image,
or get stuck in a copy cycle,
where some referent of the original object
refers back to the original object.
There are tools, such as in VisualWorks,
that scan the copy graph before copying
to work around this cyclic copying.
They work, but they are often unavoidably slow.


In addition to tools, there are algorithms that detect cycles in graphs. If such a cycle were not detectable at all, then could we not report a bug against that storage management system. I agree that it can take a long time. 


> The exact meaning of "copy" turns out to be a *really* hard problem: there is no single answer that works in all cases.

I agree one has to think out which kind of copy one wishes to do, and I agree that there is no single answer that works in all cases. But how hard is it really?

The two most common types of copies needed are true clones of everything and top-level shallow copies of just the pointers. These are provided in many languages including, for example, Java and Python. When an intermediate level of copying is required, then it might probably need to be programmed manually.

Although not always used, Ada provides the ability to provide complex data structures without passing access types. In addition, a relational model can be used, implemented in the Ada language, for example, where all data structures would be two-dimensional tables. There are actually many ways to manage the data to avoid difficulty in defining to what level one needs to copy. 

Mike




             reply	other threads:[~2002-01-22 22:35 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-01-22 22:35 Mike Brenner [this message]
     [not found] <B85AB00A.3603%verec@mac.com>
2002-01-20  5:59 ` True faiths ( was Re: The true faith ) Kaz Kylheku
     [not found] ` <gat-1101020950400001@eglaptop.jpl.nasa.gov>
     [not found]   ` <9jtu3u8cq92b05j47uat3412tok6hq <i1t28.632$XG4.38637@news2.calgary.shaw.ca>
2002-01-22 14:25     ` Copying semantics molehill (was Re: True faiths) Patrick Doyle
2002-01-22 15:47       ` Steven T Abell
2002-01-26 17:32         ` Patrick Doyle
2002-01-22 18:00       ` Kaz Kylheku
2002-01-26 17:37         ` Patrick Doyle
2002-01-28  3:08       ` Robert Dewar
2002-01-28 18:47         ` Patrick Doyle
replies disabled

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