Hacker News new | past | comments | ask | show | jobs | submit login

You can use slices.Grow for that purpose in Go. Exact sizing is only possible during slice creation.



It's unclear which policy slices.Grow exhibits, and so maybe it's not guaranteed whether you get the equivalent of Vec::reserve or Vec::reserve_exact ? My guess since it's not mentioned and no alternative is supplied is that you get Vec::reserve_exact - the same pessimisation footgun.


You get reserve, not reserve_exact. You are right that it would be allowed to implement reserve_exact semantics instead, given the method comment. But that’s not how it works, if you want reserve_exact semantics, you need to take extra steps. That said, the semantics are not exactly the same as reserve. The go compiler may optimize since allocations (I don’t know if it does though).




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

Search: