我的问题是切片长度和容量。我在这里学习:https://tour.golang.org/moretypes/11。
(我的问题被标记为可能的副本;但事实并非如此。我的问题特别是关于切掉切片的前几个元素及其含义。)
当
有没有办法恢复我们与
单击"运行"按钮后,我们得到以下信息。
号
您可以在这里阅读更多关于切片的信息。但我认为这一段回答了你的问题:
Slicing does not copy the slice's data. It creates a new slice value that points to the original array. This makes slice operations as efficient as manipulating array indices. Therefore, modifying the elements (not the slice itself) of a re-slice modifies the elements of the original slice.
号
因此,如果将切片数据分配给同一个变量,则无法恢复切片数据。
容量减少是因为通过删除前2个元素,您将更改指向新切片的指针(切片由指向第一个元素的指针引用)。
如何在内存中表示切片:。
氧化镁
号
氧化镁