help-octave
[Top][All Lists]
Advanced

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

Re: Getting arguments in oct-files - per reference or not?


From: Jordi Gutiérrez Hermoso
Subject: Re: Getting arguments in oct-files - per reference or not?
Date: Mon, 02 Jun 2014 10:10:57 -0400

On Mon, 2014-06-02 at 12:18 +0200, Daniel Kraft wrote:

> To extract arguments in an oct-file, I frequently do things like this:
> 
>     const boolNDArray inside = args(3).bool_array_value ();
>     const Matrix bdryCoords = args(4).matrix_value ();
>     const ColumnVector intsecIn = args(5).column_vector_value ();
> 
> The matrices / arrays / vectors involved can be quite large.  Now, I
> discovered that it also works if I store only a *reference*, i. e.,
> 
>     const boolNDArray& inside = args(3).bool_array_value ();
>     const Matrix& bdryCoords = args(4).matrix_value ();
>     const ColumnVector& intsecIn = args(5).column_vector_value ();
> 
> Presumably, the second form is more efficient, since it avoids an
> unnecessary copy.  However, I'm unsure if it is actually correct -- this
> depends on how the octave_value does things internally.

This is a bit of a trivial optimisation, since octave_values are COWs
(moooooo!), and they expect to own their memory.

I would dispense with the references unless you have profiled (hey,
remember that?) and determined that you really need this optimisation.

- Jordi G. H.





reply via email to

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