help-octave
[Top][All Lists]
Advanced

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

Realtime cost of call by value


From: John W. Eaton
Subject: Realtime cost of call by value
Date: Mon, 27 Oct 2003 22:01:15 -0600

On 27-Oct-2003, Glenn Golden <address@hidden> wrote:

| Octoids,

That's a new one...

| For example, I thought that if I did something like
| 
|     DEFUN_DLD  mydldfunc( ...)
|     {
|       Matrix  A(1, N);
| 
|       octave_value_list t;
|       t(0) = A;
|       innocent_function(t);
|     }
| 
| 
|     void innocent_function(octave_value_list args)
|     {
|       Matrix X = args(0).matrix_value();
| 
|       double d = X(0, 0);
|       return;
|     }

Try

     void innocent_function(octave_value_list args)
     {
        const Matrix X = args(0).matrix_value();
 
        double d = X(0, 0);
        return;
     }

instead.  Then the const version of the indexing function (which does
not force a copy) should be called.

Yes, there are some C++ tricks that could maybe be used to make it so
that no copy would happen unless the indexing operation appears on the
LHS of an assignment expression.  But I seem to remember that doing
that would require that the indexing operations and the tricky code
could not be inherited, so the code would have to be repeated in every
matrix-like class that needs indexing ops.  I'm not sure that is worth
it.

jwe



-------------------------------------------------------------
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
-------------------------------------------------------------



reply via email to

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