[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/
- [Octave-bug-tracker] [bug #51962] ++ and -- not same as +1 and -1, (continued)
- [Octave-bug-tracker] [bug #51962] ++ and -- not same as +1 and -1, Rik, 2017/09/08
- [Octave-bug-tracker] [bug #51962] ++ and -- not same as +1 and -1, Mike Miller, 2017/09/08
- [Octave-bug-tracker] [bug #51962] "A++" assigns to 'ans' while "A += 1" and "A = A + 1" do not, Rik, 2017/09/08
- [Octave-bug-tracker] [bug #51962] ++ and -- not same as +1 and -1, John W. Eaton, 2017/09/08
- [Octave-bug-tracker] [bug #51962] "A++" assigns to 'ans' while "A += 1" and "A = A + 1" do not, Rik, 2017/09/08
- [Octave-bug-tracker] [bug #51962] "A++" assigns to 'ans' while "A += 1" and "A = A + 1" do not, Rik, 2017/09/09
- [Octave-bug-tracker] [bug #51962] "A++" assigns to 'ans' while "A += 1" and "A = A + 1" do not, Michael Godfrey, 2017/09/09
- [Octave-bug-tracker] [bug #51962] "A++" assigns to 'ans' while "A += 1" and "A = A + 1" do not, Mike Miller, 2017/09/09
- [Octave-bug-tracker] [bug #51962] "A++" assigns to 'ans' while "A += 1" and "A = A + 1" do not, Michael Godfrey, 2017/09/09
- [Octave-bug-tracker] [bug #51962] "A++" assigns to 'ans' while "A += 1" and "A = A + 1" do not, Rik, 2017/09/10
- [Octave-bug-tracker] [bug #51962] "A++" assigns to 'ans' while "A += 1" and "A = A + 1" do not,
Mike Miller <=
- [Octave-bug-tracker] [bug #51962] "A++" assigns to 'ans' while "A += 1" and "A = A + 1" do not, Michael Godfrey, 2017/09/10