[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Getting arguments in oct-files - per reference or not?
From: |
Daniel Kraft |
Subject: |
Getting arguments in oct-files - per reference or not? |
Date: |
Mon, 2 Jun 2014 12:18:26 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 |
Hi all!
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.
Is it save to store the result of octave_value::matrix_value() (and
friends) in a reference, as long as the octave_value doesn't go out of
scope? Or will this be a reference to some temporary object that is not
guaranteed to persist the matrix_value() call?
Thanks! Yours,
Daniel
--
http://www.domob.eu/
OpenPGP: 901C 5216 0537 1D2A F071 5A0E 4D94 6EED 04F7 CF52
Namecoin: id/domob -> https://nameid.org/?name=domob
--
Done: Arc-Bar-Cav-Hea-Kni-Ran-Rog-Sam-Tou-Val-Wiz
To go: Mon-Pri
smime.p7s
Description: S/MIME Cryptographic Signature
- Getting arguments in oct-files - per reference or not?,
Daniel Kraft <=