help-octave
[Top][All Lists]
Advanced

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

Re: basic DLD help?


From: David Bateman
Subject: Re: basic DLD help?
Date: Wed, 13 Jul 2005 03:35:21 +0200
User-agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)

Paul Kienzle a écrit :

You have to be careful with this.  You may accidentally free the data
behind the pointer before it is used.  fortran_vec() calls make_unique(),
so it may not return the same pointer as referred to in args(0), but
instead return a pointer which is cleaned up when the temporary
args(0).vector_value() destructor is called.

Better would be to use:

    RowVector y(args(0).vector_value());
    double *py = y.fortran_vec();


Even better would be

  const RowVector y(args(0).vector_value());
  const double *py = y.fortran_vec();

since as you say fortran_vec calls make_unique except when "const", and since you aren't altering the data past to the function, in this manner you avoid a copy.

D.



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