Append to string without copy? #606
Replies: 2 comments
-
Posted at 2016-08-07 by @gfwilliams I'm pretty sure that If you're interested the code is here It won't work if the string is referenced elsewhere though:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-08-08 by @allObjects ...that would be visible in the implementation of +=... This though would mean that the interpreter would know the number of references to the string at the time of concatenation and make the copy if there are more than one references... It all depends how assignments and garbage collect work... |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-08-06 by tve
If I have a long string (say 2KB) is there a way to append to it without causing a second copy of the string to be made? E.g., does
str += "more text"
cause me to temporarily hold two copies in memory?Beta Was this translation helpful? Give feedback.
All reactions