The difference go cap and len

We must first figure out the difference between the capacity and length:
 
Capacity refers to the size of the underlying array size, length refers to the use of
 
Capacity use in what? When you use with extended length appen d, if the length is less than the new capacity, will not replace the underlying array, otherwise, go underlying array will apply for a new copy of value here in the past, lost the original array. That is, the capacity is to use: a trade-off between data memory and copy the application footprint and memory consumption.
 
The length, in order to help you limit the number of available members of a slice, the boundary providing query. So after applying make good use of space, need to be careful not to cross-border len [more]


Guess you like

Origin www.cnblogs.com/niuben/p/12310818.html