concept make in category go

appears as: make, make
Get Programming with Go

This is an excerpt from Manning's book Get Programming with Go.

18.5. Preallocate slices with make

When there isn’t enough capacity for append, Go must allocate a new array and copy the contents of the old array. You can avoid extra allocations and copies by preallocating a slice with the built-in make function.

The make function in the next listing specifies both the length (0) and capacity (10) of the dwarfs slice. Up to 10 elements can be appended before dwarfs runs out of capacity, causing append to allocate a new array.