octave-bug-tracker
[Top][All Lists]
Advanced

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

[Octave-bug-tracker] [bug #51962] "A++" assigns to 'ans' while "A += 1"


From: Mike Miller
Subject: [Octave-bug-tracker] [bug #51962] "A++" assigns to 'ans' while "A += 1" and "A = A + 1" do not
Date: Sun, 10 Sep 2017 14:47:16 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0

Follow-up Comment #10, bug #51962 (project octave):

That's what I was suggesting in comment #2, if there is a way to determine
that the "A++" expression would not be assigned to some other value and
suppress the extra copy of A made. I'm not sure that's possible, but worth
looking into.

It occurred to me that it's also worth documenting that "++A" is more
efficient than "A++". The prefix operator does not need to create an extra
copy of A. In C++ terms this is often mentioned to avoid making unnecessary
expensive copies of objects. In Octave this should be mentioned because it
avoids making expensive copies of large arrays due to Octave's COW behavior.


>> A = rand (1e4);  ## Octave allocates 800 MB
>> ++A;  ## A incremented, ans == A, no extra memory used
>> A++;  ## A incremented, ans != A, 1600 MB now used


    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?51962>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

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