mirror of
https://github.com/teivah/100-go-mistakes.git
synced 2026-06-21 08:57:07 +08:00
Merge 89c5e342f0 into c13d0b4807
This commit is contained in:
commit
2539d829d2
2 changed files with 1 additions and 1 deletions
|
|
@ -67,7 +67,7 @@ If we run this code, we see that the slice was able to cope with our request:
|
|||
[0 1 0 2 3 4 5]
|
||||
```
|
||||
|
||||
Because an array is a fixed-size structure, it can store the new elements until element 4. When we want to insert element 5, the array is already full: Go internally creates another array by doubling the capacity, copying all the elements, and then inserting element 5. Figure 4 shows this process.
|
||||
Because an array is a fixed-size structure, we cannot fit all the new elements, since there isn’t enough space for element 5. Go detects this in advance, creates another array with doubled capacity, copies the existing elements, and inserts all the new ones. Figure 4 illustrates this process.
|
||||
|
||||
<figure markdown>
|
||||

|
||||
|
|
|
|||
Binary file not shown.
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 7.4 KiB |
Loading…
Reference in a new issue