WEBVTT 00:02.840 --> 00:09.230 Welcome in his lecture, I'm going to talk about the shedder so you learn what a value actually looks 00:09.230 --> 00:09.440 like. 00:10.100 --> 00:12.920 Let's get back to the first example from the last lecture. 00:13.340 --> 00:17.830 As you can see, all these slices refer to the same baking array, right? 00:18.440 --> 00:21.470 If a slice value doesn't contain any elements. 00:21.500 --> 00:22.970 So what does it contain? 00:23.660 --> 00:25.820 How does it find its backing array? 00:26.240 --> 00:26.810 Let's see. 00:30.150 --> 00:33.400 Here are the imaginary member addresses for each member cell. 00:33.420 --> 00:35.580 Here, let me ask you something. 00:36.060 --> 00:42.810 Can you call someone directly without knowing their phone number in the same sense a slice needs to 00:42.810 --> 00:48.810 know the location or in other words, the address of its array to be able to find it on the computer 00:48.810 --> 00:49.200 memory. 00:49.920 --> 00:52.770 So it needs to store that memory address. 00:52.920 --> 00:53.340 Right. 00:53.880 --> 00:54.540 To do that. 00:54.600 --> 00:59.970 Behind the scenes, go implements the slice as a small data structure called the slice header. 01:00.180 --> 01:06.390 And in that data structure, it stores memory address of a slice as back as an example. 01:06.400 --> 01:08.670 Here is the slice header for the blue slice. 01:09.090 --> 01:12.870 It has three fields, pointer length and capacity. 01:13.440 --> 01:16.130 This is what a slice value looks like under the hood. 01:16.680 --> 01:19.770 Not that a slice Heather is not visible to you. 01:20.160 --> 01:23.070 It is used by the go wrong runtime behind the scenes. 01:23.580 --> 01:29.460 But whenever you use a slice value, you actually use this small data structure behind the scenes. 01:30.440 --> 01:35.960 The first field is the point or field, it stores the memory location of the slices Badgingarra. 01:36.500 --> 01:41.830 Think of it as the phone number of the slices making correct for this slice value. 01:41.870 --> 01:44.660 Its pointer is forty eight and the baking. 01:44.660 --> 01:48.410 Kerry's first element is located in the forty eight memory address. 01:48.860 --> 01:53.120 So the blue slice stores the memory address of the baking erase first element. 01:54.390 --> 02:00.270 Since an area is contiguous in memory so the blue skies can look ahead on the memory to find out the 02:00.270 --> 02:01.560 rest of the elements as well. 02:02.310 --> 02:05.670 So how does it know how many elements it can look for? 02:06.210 --> 02:09.500 Well, that is determined by the land here. 02:09.510 --> 02:13.530 The Blue Slicers length field is three because it has three elements. 02:14.070 --> 02:17.130 So it can only look for three more elements in the memory. 02:18.190 --> 02:24.880 The last field is the capacity to field it stores how much space, the begging actually has its doors, 02:24.890 --> 02:31.600 the length of the begging after the first element, you can get it by using the built in function like 02:31.600 --> 02:31.900 this. 02:32.410 --> 02:38.740 It's three here because the first element refers to the area's first element and there are totally three 02:38.740 --> 02:39.690 elements in the bag. 02:40.330 --> 02:43.730 So this slice sees all the elements of its back injury. 02:43.900 --> 02:46.850 I'll talk about the capacity field in more detail later on. 02:46.870 --> 02:47.440 No worries. 02:48.250 --> 02:50.290 So in summary, never forget this. 02:50.680 --> 02:53.140 The slightest value means the slice header. 02:53.490 --> 02:59.890 So when I say slice all this, think that it's a slice, either a slice is a tiny data structure with 02:59.890 --> 03:06.150 three numeric fields that describes its backing or only that it's nothing beyond that, OK? 03:07.730 --> 03:13.160 Let's take a look at the red slice, a slice, Heather, it's point of field is also forty eight. 03:13.430 --> 03:15.350 So it looks at the first element of the. 03:16.310 --> 03:20.390 This time it's Langfield is one because it has only one element. 03:20.810 --> 03:23.990 So it cannot access the rest of the elements in the area. 03:23.990 --> 03:24.470 For now. 03:24.920 --> 03:27.980 For example, let me try to index the slicers elements. 03:31.640 --> 03:37.090 As you can see, I can only index the first element, not the rest of them, they are hidden inside. 03:37.100 --> 03:38.120 It's backing away. 03:38.810 --> 03:43.400 Remember the cups, fields, stores, the length of the elements in the back. 03:43.400 --> 03:50.230 And starting from the first element here, the red slice starts from the first element. 03:50.330 --> 03:54.290 So it's, capice, these three, because there are three elements in its array. 03:56.160 --> 04:01.200 Let's take a look at the green slice now, this time the point or field is 56. 04:01.590 --> 04:04.900 So the green slices first element is not the big increase. 04:04.980 --> 04:10.710 First element, the green slice stores, the memory location of its bagging, a second element. 04:12.110 --> 04:15.060 So it cannot access the areas first elements anymore. 04:15.260 --> 04:21.680 It is because the elements that are located in member addresses before Selassie's pointer become invisible 04:21.680 --> 04:23.810 to that slice, so it cannot look back. 04:24.740 --> 04:31.700 Here, the green slice Langfield is two because it has only two elements, although there are three 04:31.700 --> 04:36.250 elements in the back injury, but for the green slice, there are two elements in there. 04:36.890 --> 04:38.930 So the green slices capacity's two. 04:39.380 --> 04:42.320 It is because the green slice cannot look back. 04:42.650 --> 04:44.930 It doesn't know about the first element. 04:46.700 --> 04:52.410 Let's take a look at a needle slice and needle slice doesn't have a back away, but it has a slice, 04:52.410 --> 04:59.720 whether it is because a slice value always has a slice, whether you remember a less value means slice. 04:59.730 --> 05:02.230 Heather, the point, the field is zero. 05:02.300 --> 05:07.440 This means that it doesn't allocate new memory for its back injury because it doesn't have one. 05:07.940 --> 05:10.300 That is why you should declare a new slice. 05:10.380 --> 05:14.500 I don't know whether you're going to add new elements to the slice or not. 05:14.930 --> 05:17.960 You never want to waste unnecessary memory space. 05:18.000 --> 05:19.550 OK, all right. 05:19.670 --> 05:20.510 That's all for now. 05:20.840 --> 05:23.810 In the upcoming lectures, you'll learn more about the sless. 05:23.810 --> 05:25.420 Heather, thank you for watching. 05:25.430 --> 05:27.380 So far, seeing the next picture of a.