help-octave
[Top][All Lists]
Advanced

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

Re: Realtime cost of call by value


From: Tomer Altman
Subject: Re: Realtime cost of call by value
Date: Tue, 28 Oct 2003 04:03:20 +0000 (UTC)

Once again, this is an indirect answer but you may want to try the
following strategy:

For your large, main Abstract Data Structures ( not Octave
'structures', necessarily ), declare them as global variables from the
main function / interpreter. Then, just pass *indices* via
call-by-value. This should give you a 'hack' that simulates
call-by-reference.

Regards,

~Tomer Altman


On Oct 27, 2003 at 8:53pm, Glenn Golden wrote:

gdg >Date: Mon, 27 Oct 2003 20:53:25 -0700
gdg >From: Glenn Golden <address@hidden>
gdg >To: address@hidden
gdg >Subject: Realtime cost of call by value
gdg >Resent-Date: Mon, 27 Oct 2003 21:53:33 -0600
gdg >Resent-From: address@hidden
gdg >
gdg >Octoids,
gdg >
gdg >I have an application in which the realtime cost of call by value
gdg >may be an issue.  While doing some measurements, I was surprised
gdg >to find that function call cost appears to be related to argument
gdg >length, even when the called function does not modify its arguments.
gdg >From what I had read in the user's manual (and here on the mailing
gdg >list) I had had the impression that this should not be the case.
gdg >
gdg >To be more specific: The following statement appears in the 2.1.50
gdg >user's manual:
gdg >
gdg >   Even though Octave uses pass-by-value semantics for function
gdg >   arguments, values are not copied unnecessarily.  For example,
gdg >
gdg >     x = rand (1000);
gdg >     f (x);
gdg >
gdg >   does not actually force two 1000 by 1000 element matrices to exist
gdg >   _unless_ the function `f' modifies the value of its argument.
gdg >
gdg >
gdg >Based on this, I assumed that the same would hold within a DLD,
gdg >i.e. the cost of calling a function should be (roughly) independent
gdg >of the length of the function args, _provided_ that the function
gdg >does not attempt to modify the value of its args, thus forcing a
gdg >copy down.
gdg >
gdg >For example, I thought that if I did something like
gdg >
gdg >    DEFUN_DLD  mydldfunc( ...)
gdg >    {
gdg >      Matrix       A(1, N);
gdg >
gdg >      octave_value_list t;
gdg >      t(0) = A;
gdg >      innocent_function(t);
gdg >    }
gdg >
gdg >
gdg >    void innocent_function(octave_value_list args)
gdg >    {
gdg >   Matrix X = args(0).matrix_value();
gdg >
gdg >   double d = X(0, 0);
gdg >   return;
gdg >    }
gdg >
gdg >   
gdg >then, based on the above statement in the manual, I expected that the
gdg >time required to execute innocent_function() should be more or less
gdg >independent of N (the dimension of A) since innocent_function() does
gdg >nothing which depends on N, nor does it attempt to modify the value of
gdg >its argument. However, this does not appear to be the case.  What I see
gdg >is that the execution time of innocent_function() is roughly proportional
gdg >to N, which suggests that copy down is occuring anyway, even though the
gdg >argument is not modified.
gdg >
gdg >Clearly I was wrong in my interpretation of the user manual. So I
gdg >was wondering if someone who is familiar with the internals of call
gdg >by value, ref counts and so on, could give a brief rundown on exactly
gdg >what copying does go on in an Octave function call, and under what
gdg >conditions. This would be of help in understanding whether what I'm
gdg >trying to do will be feasible or not, and may also be of interest to
gdg >others who are faced with similar questions about the cost of call by
gdg >value.
gdg >
gdg >
gdg >Thanks in advance,
gdg >
gdg >
gdg >Glenn D. Golden
gdg >Principal Systems Engineer
gdg >Teranetics, Inc.
gdg >
gdg >
gdg >
gdg >-------------------------------------------------------------
gdg >Octave is freely available under the terms of the GNU GPL.
gdg >
gdg >Octave's home on the web:  http://www.octave.org
gdg >How to fund new projects:  http://www.octave.org/funding.html
gdg >Subscription information:  http://www.octave.org/archive.html
gdg >-------------------------------------------------------------
gdg >
gdg >



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