Re: Pass by Reference
- Posted by Spock Jan 08, 2015
- 2631 views
Question:
For every write (eg, x[i] = n) does the internal routine check to see if "x" has a refcount [and if it has make a fresh copy] before setting the data?
Spock
I believe so, yes. Fortunately, the check a very quick operation - read one int (the refcount) and only if it's not equal to one, then make a fresh copy.
The check might be quick but it's still overhead [that could be eliminated by some radical thinking]. For operations such as, eg sorting, the performance is bound to suffer somewhat.
If there were no refcounts but there was a smarter parser lots of write operations could, I'm sure, be inlined. An extreme example would be x[i] = n resolving to a couple of machine operations.
But this would mean .. a massive rewrite.
Nah, forget I said anything.
Spock