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: Daniel Kraft
Subject: Re: Getting arguments in oct-files - per reference or not?
Date: Tue, 3 Jun 2014 09:44:13 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0

Hi Jordi!

On 2014-06-02 16:10, Jordi GutiƩrrez Hermoso wrote:
> 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.

Ok, thanks.  This sounds like the optimisation isn't correct.  I'll
probably go for copies then.

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

No, I did not do this due to profiling.  Actually, I think it doesn't
make a difference -- but for me using const references is a matter of
"good style" *as long as it is correct*.  That's why I wondered *if* it
actually is correct. ;)

Thanks again!  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

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature


reply via email to

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