Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Neither approach will reallocate.

In the append case, since the underlying slice has capacity, then each append will just extend the length. If estimated length was too small, then reallocation would occur.

In the reslice case, the new slice is a value type that points to the original underlying memory, with a length that is shorter. So no reallocation.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: