Decreasing slice capacity

You can read more about slices here. But I think this passage answers your question:

Slicing does not copy the slice’s data. It creates a new slice value that points to the original array. This makes slice operations as efficient as manipulating array indices. Therefore, modifying the elements (not the slice itself) of a re-slice modifies the elements of the original slice.

So you cannot recover the slice data if you are assigning it to the same variable.

The capacity decrease is because by dropping the first 2 elements you are changing the pointer to the new slice (slices are referenced by the pointer to the first element).

How slices are represented in the memory:
def

make([]byte, 5)

memory vis

s = s[2:4]

slice cap decrease

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)