Welcome in his lecture, I'm going to talk about the shedder so you learn what a value actually looks
like.
Let's get back to the first example from the last lecture.
As you can see, all these slices refer to the same baking array, right?
If a slice value doesn't contain any elements.
So what does it contain?
How does it find its backing array?
Let's see.
Here are the imaginary member addresses for each member cell.
Here, let me ask you something.
Can you call someone directly without knowing their phone number in the same sense a slice needs to
know the location or in other words, the address of its array to be able to find it on the computer
memory.
So it needs to store that memory address.
Right.
To do that.
Behind the scenes, go implements the slice as a small data structure called the slice header.
And in that data structure, it stores memory address of a slice as back as an example.
Here is the slice header for the blue slice.
It has three fields, pointer length and capacity.
This is what a slice value looks like under the hood.
Not that a slice Heather is not visible to you.
It is used by the go wrong runtime behind the scenes.
But whenever you use a slice value, you actually use this small data structure behind the scenes.
The first field is the point or field, it stores the memory location of the slices Badgingarra.
Think of it as the phone number of the slices making correct for this slice value.
Its pointer is forty eight and the baking.
Kerry's first element is located in the forty eight memory address.
So the blue slice stores the memory address of the baking erase first element.
Since an area is contiguous in memory so the blue skies can look ahead on the memory to find out the
rest of the elements as well.
So how does it know how many elements it can look for?
Well, that is determined by the land here.
The Blue Slicers length field is three because it has three elements.
So it can only look for three more elements in the memory.
The last field is the capacity to field it stores how much space, the begging actually has its doors,
the length of the begging after the first element, you can get it by using the built in function like
this.
It's three here because the first element refers to the area's first element and there are totally three
elements in the bag.
So this slice sees all the elements of its back injury.
I'll talk about the capacity field in more detail later on.
No worries.
So in summary, never forget this.
The slightest value means the slice header.
So when I say slice all this, think that it's a slice, either a slice is a tiny data structure with
three numeric fields that describes its backing or only that it's nothing beyond that, OK?
Let's take a look at the red slice, a slice, Heather, it's point of field is also forty eight.
So it looks at the first element of the.
This time it's Langfield is one because it has only one element.
So it cannot access the rest of the elements in the area.
For now.
For example, let me try to index the slicers elements.
As you can see, I can only index the first element, not the rest of them, they are hidden inside.
It's backing away.
Remember the cups, fields, stores, the length of the elements in the back.
And starting from the first element here, the red slice starts from the first element.
So it's, capice, these three, because there are three elements in its array.
Let's take a look at the green slice now, this time the point or field is 56.
So the green slices first element is not the big increase.
First element, the green slice stores, the memory location of its bagging, a second element.
So it cannot access the areas first elements anymore.
It is because the elements that are located in member addresses before Selassie's pointer become invisible
to that slice, so it cannot look back.
Here, the green slice Langfield is two because it has only two elements, although there are three
elements in the back injury, but for the green slice, there are two elements in there.
So the green slices capacity's two.
It is because the green slice cannot look back.
It doesn't know about the first element.
Let's take a look at a needle slice and needle slice doesn't have a back away, but it has a slice,
whether it is because a slice value always has a slice, whether you remember a less value means slice.
Heather, the point, the field is zero.
This means that it doesn't allocate new memory for its back injury because it doesn't have one.
That is why you should declare a new slice.
I don't know whether you're going to add new elements to the slice or not.
You never want to waste unnecessary memory space.
OK, all right.
That's all for now.
In the upcoming lectures, you'll learn more about the sless.
Heather, thank you for watching.
So far, seeing the next picture of a.