|
|
|
|
|
by masklinn
1474 days ago
|
|
> one good way to avoid such slice issues is to use the uncommon `a[x:y:z]` form to ensure the slice can't grow. Do you mean you always use `a[x:y:y]` in order to ensure there is no extra capacity and any append will have to copy the slice? Is append guaranteed to create a new slice (and copy over the data) if the parameter is at capacity? Because if it could realloc internally then I don't think this trick is safe. |
|
Slices are 3 word values of (ptr, len, cap). They cannot be "realloced internally", changing any of those three things requires creating a new slice.