1
00:00:01,260 --> 00:00:06,900
OK, so we're going to go over some new topics in the next section and kind of require us to know a

2
00:00:06,900 --> 00:00:09,150
little bit about the computer's memory.

3
00:00:09,630 --> 00:00:13,170
So I'm going to provide a quick explanation on that.

4
00:00:13,560 --> 00:00:19,650
And then later on in the course, I will go a little bit deeper in a computer memory so we can really

5
00:00:19,650 --> 00:00:24,600
get into the weeds and you can understand what's going on under the hood in that digital kind of imaginary

6
00:00:24,600 --> 00:00:25,590
space on your computer.

7
00:00:27,300 --> 00:00:30,810
So where does the information in our code get stored?

8
00:00:31,050 --> 00:00:37,530
So we've talked a bit about the compilation process of using the C++ compiler, right?

9
00:00:37,530 --> 00:00:43,200
But what happens when we actually run our program, what's happening inside of our computer?

10
00:00:43,200 --> 00:00:44,130
What is it doing?

11
00:00:46,050 --> 00:00:53,670
So what happens from a very high level view is that our executable that we've created from the compilation

12
00:00:53,670 --> 00:00:57,150
process also can be referred to as our binary program.

13
00:00:57,780 --> 00:01:01,500
It gets loaded into a place we call virtual memory.

14
00:01:03,160 --> 00:01:07,990
So another note here, you know, operating systems and memory management are complex right now, we're

15
00:01:07,990 --> 00:01:11,020
just looking at it from a bird's eye view of very bird's eye view.

16
00:01:11,890 --> 00:01:17,590
Later, we're going to go a little bit more into memory and I say a little bit because this is an operating

17
00:01:17,590 --> 00:01:20,560
systems course or a computer architecture course.

18
00:01:20,980 --> 00:01:28,720
I just want to kind of give you on the tools you need to be able to write software and understanding

19
00:01:28,720 --> 00:01:32,110
memory and addresses and things like that are important.

20
00:01:32,590 --> 00:01:34,720
So I will have to go into it a little bit.

21
00:01:36,520 --> 00:01:39,050
So what is this virtual memory thing that I just mentioned?

22
00:01:39,070 --> 00:01:42,370
Well, we call it virtual because it's not a physical thing.

23
00:01:42,700 --> 00:01:48,460
We do have some physical things on our computer that deal with memory, and that would be RAM and the

24
00:01:48,460 --> 00:01:49,600
hard disk drive.

25
00:01:49,780 --> 00:01:55,070
So the hard disk drive is basically the spinning disk on your computer.

26
00:01:55,090 --> 00:02:00,760
It can be made of silicon and metal and plastic and stuff, and has a little reading and writing head

27
00:02:01,180 --> 00:02:07,360
that you can think of kind of like a like record player or something like that.

28
00:02:08,740 --> 00:02:15,520
But that is something that stores memory permanently the hard disk drive.

29
00:02:16,000 --> 00:02:21,190
So it's something we would call non-volatile, so you turn your computer off and stuff is still stored,

30
00:02:21,190 --> 00:02:24,940
you don't you lose all your files that you've saved onto the hard disk drive.

31
00:02:26,450 --> 00:02:33,380
You also can have a hard disk that is not necessarily a disk, it's kind of like maybe a solid state,

32
00:02:33,380 --> 00:02:37,400
so you might have that in your computer so it doesn't use a spinning disk, but essentially the same

33
00:02:37,400 --> 00:02:37,730
thing.

34
00:02:38,780 --> 00:02:45,500
The RAM is also a physical thing that you can touch their sticks of RAM memory on your computer.

35
00:02:46,550 --> 00:02:52,190
That's what a lot of people refer to when they're talking about memory, and that is something we refer

36
00:02:52,190 --> 00:02:55,470
to as volatile storage, so it is not there.

37
00:02:55,490 --> 00:02:58,820
Once you turn your computer off all the data in there, it gets wiped in the RAM.

38
00:02:59,510 --> 00:03:01,510
But the virtual memory is something else.

39
00:03:01,520 --> 00:03:04,720
So you can basically think that it is.

40
00:03:04,730 --> 00:03:06,650
You can imagine it being in RAM.

41
00:03:07,340 --> 00:03:11,030
Somewhere where our programming was stored is pretty complex.

42
00:03:11,030 --> 00:03:17,060
It's managed by the operating system, but we're just going to imagine it somewhere in RAM and it's

43
00:03:17,060 --> 00:03:18,680
just an imaginary space.

44
00:03:18,680 --> 00:03:20,540
It is not physical, it's not.

45
00:03:20,540 --> 00:03:21,890
So it's not a physical thing.

46
00:03:21,890 --> 00:03:29,930
It's just some kind of area like set aside, you know, that RAM, your RAM has a certain amount, right?

47
00:03:30,830 --> 00:03:36,980
So you might have, you know, whatever amount of RAM on your computer and you'll have this virtual

48
00:03:36,980 --> 00:03:40,880
space, this part of RAM, where our computer program can get loaded.

49
00:03:42,030 --> 00:03:46,140
So it's a little more complicated than that, but that's what we're going to imagine it is right now.

50
00:03:47,640 --> 00:03:54,750
So some other things to talk about is there's big distances between some of these locations where you

51
00:03:54,750 --> 00:03:56,280
can grab your data from.

52
00:03:56,280 --> 00:04:02,430
So I'm going to compare RAM and the hard disk drive with some illustrations.

53
00:04:03,030 --> 00:04:07,680
Another note down here remember that RAM is only volatile, so it's temporary.

54
00:04:07,680 --> 00:04:11,760
When the computer turns off, the data goes away.

55
00:04:11,790 --> 00:04:12,060
Right?

56
00:04:13,050 --> 00:04:14,820
So let's look at a little analogy here.

57
00:04:14,830 --> 00:04:19,020
So here's a room this square that's gray, and here is you.

58
00:04:20,500 --> 00:04:27,670
And here is another room, and here is some data, so this could be like RAM, so let's say you're here.

59
00:04:27,730 --> 00:04:33,580
If you wanted to get something from RAM, it could be kind of analogous to going out of this room into

60
00:04:33,580 --> 00:04:35,380
another room and getting the data.

61
00:04:36,280 --> 00:04:42,940
If we want to compare that though, with getting something from the hard disk drive and I'm talking

62
00:04:42,940 --> 00:04:48,610
about like you being able to get some data for your program, you know, needing to fetch some data

63
00:04:48,610 --> 00:04:52,150
that's needed in your program that's running in that virtual address space.

64
00:04:52,720 --> 00:04:57,880
How far would you need to go when you're trying to get something from RAM compared to getting something

65
00:04:57,880 --> 00:04:58,780
from hard disk drive?

66
00:04:59,710 --> 00:05:02,440
So this is what it would be like on the hard disk drive.

67
00:05:02,770 --> 00:05:08,860
It would be analogous to you being here on planet Earth and you having to go all the way to Pluto to

68
00:05:08,860 --> 00:05:10,330
get the data and back.

69
00:05:12,470 --> 00:05:18,950
So it may seem kind of weird to say something like that, but really when you look at the numbers like

70
00:05:19,040 --> 00:05:25,100
how far away stuff is and RAM compared to how far away stuff is in the hard disk drive.

71
00:05:26,010 --> 00:05:29,880
It really is massive in terms of what the computer sees.

72
00:05:30,900 --> 00:05:34,510
So you might not notice that at all because everything seems really fast, right?

73
00:05:34,530 --> 00:05:41,070
Like you get stuff pretty much instantly from RAM and you pretty much get stuff instantly from the hard

74
00:05:41,070 --> 00:05:44,850
disk drive or the computer's moving really, really fast.

75
00:05:44,850 --> 00:05:47,910
And it's making like some really quick calculations.

76
00:05:48,480 --> 00:05:58,350
But if you look at the factor of like how much farther by what factor you need to multiply by to show

77
00:05:58,350 --> 00:06:02,580
the difference in distance between going to RAM and going to the hard disk drive.

78
00:06:03,700 --> 00:06:11,860
It would be something analogous to you having to physically go grab like pieces of paper that were data

79
00:06:12,160 --> 00:06:16,510
in another room and instead having to make a spaceship and go out to Pluto to get it.

80
00:06:17,200 --> 00:06:23,080
So pretty crazy and definitely really interesting when you think about the inner workings of the computer.

81
00:06:23,770 --> 00:06:30,610
Another reminder is that the hard disk drive is non-volatile, so thankfully we are able to save our

82
00:06:30,610 --> 00:06:36,460
documents and music and movies in a place that does not go away when the computer turns off.

83
00:06:39,770 --> 00:06:44,750
So another important thing about this virtual memory land is it has addresses.

84
00:06:44,990 --> 00:06:49,850
So imagine the virtual memory area as an incredibly huge parking lot.

85
00:06:51,120 --> 00:06:57,030
So this parking lot has a lot of different areas based on what type of cars are allowed to park there,

86
00:06:57,930 --> 00:07:04,170
and I'm using that analogy because there are different sections of memory that are kind of meant to

87
00:07:04,200 --> 00:07:05,680
handle different things.

88
00:07:06,960 --> 00:07:14,640
Each parking space in this parking lot is the same size and has a number associated with it so you can

89
00:07:14,640 --> 00:07:15,450
find your car.

90
00:07:15,900 --> 00:07:22,530
You can think of this as an address, and that is what we will be referring to these locations in the

91
00:07:22,530 --> 00:07:25,740
virtual memory space, as we would call them, addresses.

92
00:07:27,850 --> 00:07:34,990
So the memory addresses in this virtual memory land are represented in hexadecimal form, so you should

93
00:07:34,990 --> 00:07:37,960
be familiar with something like this, you've seen it before.

94
00:07:37,960 --> 00:07:43,810
We talked a little bit about binary and hex and decimal and octal and stuff like that.

95
00:07:45,070 --> 00:07:47,140
So here are some examples.

96
00:07:47,590 --> 00:07:53,180
So you see this number right here as high as zero X, that is actually not part of the address.

97
00:07:53,200 --> 00:07:56,410
This is just something you prepend to the address to tell you.

98
00:07:56,410 --> 00:07:59,200
It is Hex, so the zero x just means Hex.

99
00:07:59,800 --> 00:08:06,070
After it, you might see an h sometimes, but that's pretty rare in that also can mean hex like a lowercase

100
00:08:06,070 --> 00:08:06,400
h.

101
00:08:06,880 --> 00:08:08,350
People refer to it as that.

102
00:08:08,920 --> 00:08:15,760
So this cluding this right here we see one two three four five six seven eight f's.

103
00:08:16,510 --> 00:08:18,850
And here we see eight zeros.

104
00:08:20,270 --> 00:08:27,470
So basically, the zeros you can imagine as like in the very first parking spot.

105
00:08:27,800 --> 00:08:36,450
So at the very like, you know, this is the closest spot and the eight F's would be the highest number

106
00:08:36,450 --> 00:08:38,090
of spot, maybe like the farthest away.

107
00:08:38,990 --> 00:08:42,590
So this is the numbering system going from zero up to F.

108
00:08:42,590 --> 00:08:47,060
And that is, of course, because we're using the hex system, you know, where we're not just using

109
00:08:47,060 --> 00:08:51,770
numbers, we also have those letters being kind of the highest one in that base.

110
00:08:51,770 --> 00:08:53,960
16 Hex numbering system.

111
00:08:55,530 --> 00:09:01,800
And the reason that there are eight here is because.

112
00:09:02,940 --> 00:09:09,750
We are looking at something we could refer to as a 32 bit address space, so you might have heard of

113
00:09:09,750 --> 00:09:18,270
something about what your computer's operating system really is in terms of the architecture.

114
00:09:18,270 --> 00:09:25,020
So maybe when you look at details about your laptop or something like that or your desktop, you're

115
00:09:25,020 --> 00:09:29,010
looking at details about the OS, whether it be Windows or Mac or something like that.

116
00:09:29,640 --> 00:09:36,750
You might see like, Oh, I have 32 bit windows or I have 64 bit windows, and that's just talking about

117
00:09:36,750 --> 00:09:45,600
this type of operating system and also talking about the address space that you would have 32 or 64

118
00:09:45,600 --> 00:09:45,930
bit.

119
00:09:46,890 --> 00:09:54,810
So remember that we kind of used to hex characters to represent a bite.

120
00:09:55,200 --> 00:09:57,550
So each one could be four bits, right?

121
00:09:57,570 --> 00:09:58,950
Four bits here, four bits.

122
00:09:58,950 --> 00:10:00,210
They're eight bits.

123
00:10:00,210 --> 00:10:01,500
Make up a byte, right?

124
00:10:02,010 --> 00:10:07,350
And so if we kind of look at that here, here's eight eight bits, right?

125
00:10:09,150 --> 00:10:12,300
So if we said we had eight ifs here, right?

126
00:10:12,570 --> 00:10:19,650
So if we take this eight bits, which is a byte right here, you know, how many bytes do we have in

127
00:10:19,650 --> 00:10:19,890
here?

128
00:10:19,920 --> 00:10:21,540
Well, we have four of these, right?

129
00:10:21,930 --> 00:10:22,970
So here's one.

130
00:10:22,980 --> 00:10:25,170
You know, every two of them can be a byte.

131
00:10:25,180 --> 00:10:28,890
So we have one two three four.

132
00:10:29,430 --> 00:10:32,820
And so how many bytes are in here?

133
00:10:32,850 --> 00:10:33,240
Well.

134
00:10:35,240 --> 00:10:36,440
Or how many bits, sorry.

135
00:10:36,770 --> 00:10:39,530
It would be 32 bits, right?

136
00:10:40,160 --> 00:10:43,610
So we have four bytes or 32 bits.

137
00:10:44,450 --> 00:10:49,310
So you see these eight big chunks, eight times for thirty two, and that is synonymous with us talking

138
00:10:49,310 --> 00:10:50,990
about this 32 bit address space.

139
00:10:51,290 --> 00:10:56,600
You might also have seen you might be seeing your addresses in 64 bit.

140
00:10:57,770 --> 00:10:59,840
That can be kind of different.

141
00:11:00,560 --> 00:11:08,150
Sometimes they only show the, let's say, first 12 characters there.

142
00:11:09,470 --> 00:11:13,850
So that might be kind of confusing, but there could be like, you know, leaning chairs and stuff like

143
00:11:13,850 --> 00:11:14,150
that.

144
00:11:14,780 --> 00:11:19,310
But just wanted to use this 32 bit one to kind of help you understand it better.

145
00:11:21,990 --> 00:11:27,210
So this could be a theoretical piece of this virtual memory address land.

146
00:11:27,660 --> 00:11:31,050
And you can see that we are counting up in the addresses.

147
00:11:31,050 --> 00:11:32,970
So here are the parking spots.

148
00:11:33,210 --> 00:11:36,330
I mean, these would be like the places we could store our data, right?

149
00:11:37,020 --> 00:11:41,430
So you see it says one and two and three and four, and these are hex addresses.

150
00:11:41,430 --> 00:11:46,500
So it'll look a little something probably not exactly like this if you were to examine your computer

151
00:11:46,500 --> 00:11:48,840
memory, but something like this.

152
00:11:52,250 --> 00:11:59,300
So remember that these are represented in hexadecimal and they would start at like zero and go all the

153
00:11:59,300 --> 00:12:01,820
way up to all these efforts right here.

154
00:12:04,280 --> 00:12:07,370
So talk a little about that, a little bit about memory.

155
00:12:07,640 --> 00:12:13,790
But we should also talk a little bit about what we're going to get into in the next session, which

156
00:12:13,790 --> 00:12:14,750
is containers.

157
00:12:14,760 --> 00:12:16,610
So it's great and all that.

158
00:12:16,610 --> 00:12:22,610
We've been using variables like single variables, of course, you know, like making an integer or

159
00:12:22,610 --> 00:12:28,580
a float or something like that, but it limits us quite a bit to only be able to use single variables

160
00:12:28,580 --> 00:12:29,420
to store stuff.

161
00:12:29,900 --> 00:12:33,590
Wouldn't it be nice if we could store than one more than one piece of data?

162
00:12:33,590 --> 00:12:40,700
So like more than one end kind of in the same area, maybe we want to group a bunch of cars together

163
00:12:40,700 --> 00:12:44,150
moving forward with this analogy and park them right next to each other.

164
00:12:45,170 --> 00:12:52,070
So maybe we would want four cars parked right here next to each other in this virtual address space.

165
00:12:53,200 --> 00:12:59,800
So in the next few lectures, we're going to start using some basic containers where we can group our

166
00:12:59,800 --> 00:13:05,530
data and manipulate it so we can do more interesting things if you have a lot of your data stored in

167
00:13:05,530 --> 00:13:07,240
the same location.

168
00:13:07,480 --> 00:13:14,290
You can kind of combine that data in interesting ways and have a better type of organization of your

169
00:13:14,290 --> 00:13:14,890
program.

170
00:13:15,790 --> 00:13:19,390
It also makes it easier to write more complex programs.

171
00:13:21,430 --> 00:13:28,390
So with that, I'm going to leave you with this lecture, and we will then get into talking about these

172
00:13:28,390 --> 00:13:30,010
containers that I've talked about.

173
00:13:30,280 --> 00:13:36,580
If you are confused about the addressing when we go through the lecture again, or you could look up

174
00:13:36,580 --> 00:13:44,860
some additional information on how the address space works, we're going to be talking about how these

175
00:13:44,860 --> 00:13:53,350
containers kind of look in memory and where our stuff is stored in relation to the other stuff.

176
00:13:53,550 --> 00:13:56,560
When I say stuff, I mean, like variables like integers.

177
00:13:56,980 --> 00:13:59,750
Where is one integer compared to the next integer?

178
00:13:59,770 --> 00:14:03,220
How does it look if we put that in one of these containers that I'm talking about?

179
00:14:04,210 --> 00:14:04,540
All right.

180
00:14:04,540 --> 00:14:06,430
So with that, I will see you in the next lecture.
