In this lecture, we cover a practical Go technique: how to preallocate slice capacity with
make(...,
0,
cap) so that
append inside a loop reallocates and copies elements less often. You will see the difference between
make([]T, n) and
make([]T, 0, n), an example of building a task list (TaskBox), a way to “see” reallocations by tracking changes in
cap, and common mistakes when working with slices.