help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: IDL's temporary() function


From: John W. Eaton
Subject: Re: IDL's temporary() function
Date: Tue, 22 Apr 2008 14:07:26 -0400

On 22-Apr-2008, Judd Storrs wrote:

| > a *= 5;
| > a += 1;
| 
| 
| I think this only works when A is already writable without copy in the
| current scope already. i.e.
| 
| function A = test(A)
|   A *= 5;
|   A += 1;
| end

In Octave,

  X OP= Y

is just syntactic sugar and completely equivalent to

  X = X OP Y

so there is nothing gained here.

| A = test(A);
| 
| will allocate a duplicate of A, I think. The idea is that in this case
| 
| A = test(temporary(A))

You might be able to implement a function with the semantics you want
just by manipulating reference counts.  It would still result in
copies for cases like

  B = A;
  A = test (tempoarary (A));

since the assignment to B also increments the reference count, or for
cases like

  function f (A)
    A = test (temporary (A))
    ...

since the value passed in to the fucntion F will have a reference
count greater than 1.

| will remove A from the scope of the caller and transport it into the
| function's scope and mark it as writable so that the multiplication doesn't
| cause A to be duplicated.

We've discussed pass-by-reference before on the maintainers list.  I
think the consensus was that we should recognize cases like

  function a = f (a)

and automatically note that the value passed is the value returned and
do the appropriate optimization, but perhaps only when the call is
also of the same form(?):

  a = f (a)

But this might not be trivial to implement.

In any case, I'd recommend subscribing to the maintainers list and
continuing the discussion there.

jwe


reply via email to

[Prev in Thread] Current Thread [Next in Thread]