Apr 23, 2020

[Go] slice increase by factor

Discussion thread:
https://groups.google.com/forum/#!msg/golang-dev/Rou6d5xR5QU/bBOnEzukAwAJ

In C++, as in FaceBook's folly library doc:
https://github.com/facebook/folly/blob/master/folly/docs/FBVector.md#memory-handling and the behavior is well-known.

For Go slice, simple,
"""
if the current length is less than 1024 we double the capacity, and otherwise we increase the capacity by 25%. https://golang.org/src/runtime/slice.go#L66
"""

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.