Why can't you just use the array instead of slice with make, if you know the size?
@nishantrao56004 жыл бұрын
I dont see the point of the capacity function yet. Where is it actually useful?
@FrequenciaJogos7 жыл бұрын
But what is the benefit of using a capacity? It will grow up if exceed, I don’t get the point. The size is ok, you say the slice will hold X values. But, the capacity, I don’t understand the advantage.
@rajbirbhattacharjee9056 жыл бұрын
This is similar to the vector implementation in C++. Arrays that can grow. Every time you add an element, it is a O(1) operation till you reach the capacity, at which point it becomes O(n) for the next insert.
@brownbearnishant4 жыл бұрын
what if we don't know how much number of elements the slice is going to take in what to do for that???