← 返回刚才阅读的位置

知识卡片

结构图卡 · 4545.g.8.c

切片视图共享底层数组

理解等级:中级

数组长度属于类型且固定;切片由底层数组指针、长度与容量组成,描述数组中的一段。两个切片可能指向同一数组,修改重叠元素会互相可见;append返回新的切片视图,增长时也可能换底层数组,因此必须接收返回值,不能假定所有扩展仍共享。图展示表示关系,节点名称是示意,不是新增的Go定义类型。

结构图: 类图:

classDiagram
 class SliceView["切片表示(示意)"] {
  data
  len
  cap
 }
 class BackingArray["底层数组(示意)"]
 SliceView --> BackingArray : 引用一段
这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • Go Language Foundations · 查看原书依据

      In actuality, each slice is represented by a lightweight data structure with three components: a pointer to some element of a backing array that represents the first element of the slice, not necessarily the first element of the array; a length, representing the number of elements in the slice, and a capacity, which represents the

    参考来源

    - 位置:《Cloud Native Go》第03章《Go Language Foundations》(来源项目book-sources;源文件:extracted/Cloud Native Go (Matthew A. Titmus)/_epub-src/OEBPS/ch03.xhtml) - 结论依据:数组长度属于类型且固定;切片由底层数组指针、长度与容量组成,描述数组中的一段。原文相应定义、示例或限制为此结论提供依据;补充纠错与版本边界在正文就近标明。 - 原始内容:In actuality, each slice is represented by a lightweight data structure with three components: a pointer to some element of a backing array that represents the first element of the slice, not necessarily the first element of the array; a length, representing the number of elements in the slice, and a capacity, which represents the