In the following code, I would expect 3 total string allocations to be made:
String str = "abc";
String str2 = str*2; //"abcabc"
- 1 when creating
str - another when creating a copy of str to concatenate with itself
- a third to hold the concatenation of str with itself (
str2)
Are there fewer or more allocations made in this example? I know that strings are immutable in Dart but I'm unsure how these operations work under the hood because of this property.
Aucun commentaire:
Enregistrer un commentaire