Why have arrays in Go?

前端 未结 4 684
北海茫月
北海茫月 2020-11-27 05:46

I understand the difference between arrays and slices in Go. But what I don\'t understand is why it is helpful to have arrays at all. Why is it helpful that an array type de

4条回答
  •  鱼传尺愫
    2020-11-27 06:15

    Every array could be a slice but not every slice could be an array. If you have a fixed collection size you can get a minor performance improvement from using an array. At the very least you'll save the space occupied by the slice header.

提交回复
热议问题