August 2019
Beginner to intermediate
798 pages
17h 2m
English
Slices have two main properties: capacity and length. The tricky thing is that usually these two properties have different values. The length of a slice is the same as the length of an array with the same number of elements and can be found using the len() function. The capacity of a slice is the current room that has been allocated for this particular slice and can be found with the cap() function. As slices are dynamic in size, if a slice runs out of room, Go automatically doubles its current length to make room for more elements.
Putting it simply, if the length and the capacity of a slice have the same values and you try to add another element to the slice, the capacity of the slice will be doubled whereas ...
Read now
Unlock full access