[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Realtime cost of call by value
From: |
pkienzle |
Subject: |
Re: Realtime cost of call by value |
Date: |
Mon, 03 Nov 2003 20:16:27 -0000 |
On 3 Nov 2003 at 14:37, Geraint Paul Bevan wrote:
> I like the idea of creating references to objects other than function
> arguments even more. In particular, I would like to be able to create
> references to substructures in large data structures and have the
> underlying data altered:
>
> for &my_substructure = some.large.data.structure.
> manipulate(my_substructure)
>
References make it more difficult for people trying to
understand the program. I think we should be looking for
ways of doing the what we want without using references.
For example, instead of f(A) where f modifies A, we could
write A=f(A). Then it is clear to the reader that A is being
updated.
The current discussion started because A = f(A) is
not implemented efficiently. With a little post processing
on a tree_statement structure, we could identify the item
which appears on the RHS of the assignment and mark
it as reusable. After rearranging liboctave so that it can
do in place operations, this would eliminate the worst of
the abuses.
There are more difficult cases, such as
b = 3*a;
a = [];
where we can't tell that a is reusable until we look at the next
statement. More complicated analysis on tree_statement_list
would show us those. Beyond that, it is up to the user to
say A=[] when the value of A is no longer needed so that such
simple static analysis will work.
This doesn't help for some.large.data.structure though,
even if you are using helper functions. For that you
need to handle even more difficult constructs like
x.y = 3*x.y and x{j} = 5*x{j}.
The only place a reference is unavoidable is if you want
to create a self-referential data structure. Even in those
cases you could simulate it in the usual fortran style: an
array of nodes and integer indices instead of pointers.
Paul Kienzle
address@hidden
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------