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: Glenn Golden
Subject: Realtime cost of call by value
Date: Mon, 27 Oct 2003 20:53:25 -0700

Octoids,

I have an application in which the realtime cost of call by value
may be an issue.  While doing some measurements, I was surprised
to find that function call cost appears to be related to argument
length, even when the called function does not modify its arguments.
>From what I had read in the user's manual (and here on the mailing
list) I had had the impression that this should not be the case.

To be more specific: The following statement appears in the 2.1.50
user's manual:

   Even though Octave uses pass-by-value semantics for function
   arguments, values are not copied unnecessarily.  For example,

     x = rand (1000);
     f (x);

   does not actually force two 1000 by 1000 element matrices to exist
   _unless_ the function `f' modifies the value of its argument.


Based on this, I assumed that the same would hold within a DLD,
i.e. the cost of calling a function should be (roughly) independent
of the length of the function args, _provided_ that the function
does not attempt to modify the value of its args, thus forcing a
copy down.

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

        
then, based on the above statement in the manual, I expected that the
time required to execute innocent_function() should be more or less
independent of N (the dimension of A) since innocent_function() does
nothing which depends on N, nor does it attempt to modify the value of
its argument. However, this does not appear to be the case.  What I see
is that the execution time of innocent_function() is roughly proportional
to N, which suggests that copy down is occuring anyway, even though the
argument is not modified.

Clearly I was wrong in my interpretation of the user manual. So I
was wondering if someone who is familiar with the internals of call
by value, ref counts and so on, could give a brief rundown on exactly
what copying does go on in an Octave function call, and under what
conditions. This would be of help in understanding whether what I'm
trying to do will be feasible or not, and may also be of interest to
others who are faced with similar questions about the cost of call by
value.


Thanks in advance,


Glenn D. Golden
Principal Systems Engineer
Teranetics, Inc.



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