#is this a slice or an array ?
54 messages · Page 1 of 1 (latest)
even with a size ? it is still a slice ?
That's an array
[x] - array
[] - slice
but
hmmmmmm confusing
soooo
when i use the make function
to make a slice with a length
it is like i already calculated the length right ?
I don't understand
Yes
so
when i do this
tst := []string{"hello"}
and i use the len() function
the len function will return the length right ?
Yes
I think so? Maybe there is an exception but I can't think of one right now
i seeeee
What's to remember is that arrays are static and can't be expanded, while slices can be appended to
@prisma cedar
- slices: runtime length and cap stored in the slice header
- arrays: compile-time length and cap stored in the type definition
wait wait wait
a slice have a size, everything has a size
slice already have the length why do we need capacity???????????
the length of the slice is set at runtime and is not part of the type
that so append can be O(1)
what is O(1) ????
wikipedia, google, youtube, chatgpt, ... are all able to explain you this
fine
can i ask you one question ?????
.reserve(...) is a method you might've seen in the API of your favorite dynamic array (or hash table or whatnot), and it's an excellent tool for making simple, impactful performance optimizations while you are building up data structures. But just like all tools, it has sharp edges. In this video we'll dive into where .reserve() can make your pe...
I have no clue, just ask your question
why did you name yourself young corruptor ?????

slices use an array under the hood.
the capacity is the size of that hidden array, and the size is how many items you are currently using.
it is like a convenient array that can automatically grow
The capacity of a slice is the size of the underlying array.
The length of a slice is how much of the underlying array you're using.