ZhangZhihui's Blog  

 

 

 

 

 

 

Converting one slice type into another is a frequent operation for Go developers. As we have seen, if the length of the future slice is already known, there is no good reason to allocate an empty slice first. Our options are to allocate a slice with either a given capacity or a given length. Of these two solutions, we have seen that the second tends to be slightly faster. But using a given capacity and append can be easier to implement and read in some contexts.

posted on 2024-02-15 09:56  ZhangZhihuiAAA  阅读(4)  评论(0编辑  收藏  举报