help-octave
[Top][All Lists]
Advanced

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

Re: Get pointer to data in Matrix classes [possible solution]


From: José Luis García Pallero
Subject: Re: Get pointer to data in Matrix classes [possible solution]
Date: Thu, 12 Mar 2009 13:23:39 +0100

No, no, no, that's bad - Octave just doesn't work this way. If you do
this, you can modify something else.
Consider:

b = my_b;
my_tr_solve (A, b);

if my_tr_solve uses const_cast on data (), my_b will still share the
data with b and will be also modified (!)

In short, you can use this method, in rare cases and *extremely*
carefully, if it's just an internal use and you *know*  the variable
passed to the function is not aliased (a local temporary, for
instance).
But I advise you not to - if you really need to save memory at this
level, it's probably better to stay in C++ all the time.

There have been several discussions about the possibility of somehow
optimizing calls like x = myfunc (x), but it's not a trivial problem.

Ok, thank you. Your example

b = my_b;
my_tr_solve (A, b);

was the definitive argument for me. For read-only data I'll use data() method and for write I'll use fortran_vec().

--
*****************************************
José Luis García Pallero
address@hidden
(o<
/ / \
V_/_
Use Debian GNU/Linux and enjoy!
*****************************************

reply via email to

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