Some Basics Concerning RAM

tonyhan774·2021년 2월 10일

Basic of C language

목록 보기

Unlike data that is stored on disk, RAM memory exist while only your computer is turned on.
As soon as you turn off the computer, everything that was stored on your RAM is gone.
That is why if you were working on a document and forgot to save it, you cannot get it back.
When you run a program on your computer, that program makes use of your RAM to store and retrieve all sorts of data. For example, if you load a document in a word processor, the content of the document can be loaded into your RAM and then the program can manipulate the document as you edit it.
When you are satisfied you tell the program to save your document and this causes your program to take what was in RAM and store it onto your disk for permanent storage. Now if you have 4GB of RAM, that means roughly 4 billion bytes or 4 billion sets of 8 ones and zeros available for any program that is running on your computer. Your operating system is responsible for ensuring that each program has enough RAM to use and for making sure that the RAM in use by one program cannot be used by another program. Every one of those sequences of eight ones and zeros has an address.
The addresses start at 0 and work their way upto 4 billion. The exact way that this is done is more
complex but for right now this is a simple enough description.
You as a programmer need to store data at a specific address in memory and then you need to be able to know where it is for later on.
Now let's say I have a string of text.

"Hello Tony"

and I put this to RAM. If I want to, later on, display that text, first of all,
I have to retrieve it from RAM. That means I must know where in RAM, the string of text was put or in other words, I have to know what address this string of text is located in memory.
However, it would be quite tedious if I had to remember some enormous number as an address in memory every time I need to store something. This leads us to the next role that a programming language has. All programming language have functionality that keeps track of these addresses for us and allows us to use plain English names in place of addresses as well as for the contents of what we store. Now, here is an example of this in action.

RAM Addresses
2,313,123,123 <--"Hello Tony"

We have no idea where the programming language decided to put our data. So what a programming language can do is basically allow you to use a simple
word and that word becomes equivalent for the address in memory. So, in a programming language, what I would probably write would be something like this,

Tony_text = "Hello Tony"

(Programming language will automatically convert "Tony_Text" to
2,313,123,123 or whatever the address happens to be.)

This is what we really need to worry about as a programmer.
I do not have to worry about everything that goes on behind the scenes although I do have to understand it.
So, when I write Tony_text = "Hello Tony", here is that it happens,

  1. The text, actual data(Hello Tony) gets placed into memory at some address

  2. The programming language will automatically understand whenever it sees Tony_text, it will understand what I am referring to is the actual place in memory that the data is stored.

We need to keep in mind that programming language is actually keeping track of three different things,
1) Actual memory address(2,313,123,123 in this case)
2) The name that corresponds to that memory address of where the data is actually stored
3) Data itself that is stored at that particular location in memory.

Learning IT in Vietnam

0개의 댓글