Learn IT with Davo
  • Mr Davidson's Blog
  • Twitter
  • A Level CS
    • A Level Exam Technique
    • Lessons
    • Unit 3 - Coursework Guidance
  • OLD GCSE CS - J276
    • All GCSE Questions
    • GCSE Exam Technique
    • Lessons
    • Glossary of Terms
    • Unit 1 Revision >
      • 1.1 - Systems Architecture
      • 1.2 - Memory
      • 1.3 - Storage
      • 1.4 - Wired and Wireless Networks
      • 1.5 - Topologies, Protocols and Layers
      • 1.6 - System Security
      • 1.7 - Systems Software
      • 1.8 - Ethics and Law
    • Unit 2 Revision >
      • 2.1 - Computational Thinking
      • 2.1 - Searching and Sorting Algorithms
      • 2.1 and 2.2 - Writing Algorithms/Programming Techniques
      • 2.2 - SQL and Database Structure
      • 2.3. Robust Code
      • 2.4. Logic
      • 2.5. Translators and Facilities
      • 2.6. Data Representation
  • NEW GCSE CS - J277
    • Glossary of Terms
    • Exam Technique
    • Lessons >
      • Unit 1 - Computer Systems
  • GCSE Business - J204
    • Lessons >
      • Unit 1 - Business Activity, Marketing and People
      • Unit 2 - Operations, Finance and Influences
    • Exam Technique
  • Contact

1.2 - Memory

In this section (click to jump):
  • What is RAM?
  • What is ROM?
  • The difference between RAM and ROM
  • Performance
  • The concept of Virtual Memory
  • Types of Memory
  • Revision/Long Answer Summary Table
PictureA game about an heroic egg who saves his egg friends. What else do you want?
Some of the most common mistakes in any computer science exam ​are made when answering questions on Memory and Storage. Often, for some reason, students just can't get their head around the difference between the two, even though they should be quite clear.

To understand both of these things you need to understand what a computer does - you should already know this from the previous section on the CPU. If you don't, you definitely need to go back and read that first. To summarise, the job of the CPU (and therefore the computer) is to fetch, decode and execute instructions.

What are these instructions that the CPU carries out? Software. We have to remember that everything you do or see on a computer is software. This website is being shown to you through software (your web browser), your favourite game is software, that last video you watched on YouTube... all of it is nothing more than a list of instructions, whether you find that hard to believe or not, it's true!

These instructions have to go somewhere! When computers first began to appear, programs had to be physically typed in to the machine every time you wanted to use them. If you turned the computer off, you would have to type them in again! This was no easy task, you'd sit there as a kid staring at a magazine with a three page program listing, written in size 5 font so you can only just read it and you'd think "this'll be amazing! it has to be! look at all the stuff here."

Inevitably it was utterly, utterly awful. But, the side effect was that by the age of 8 you were already an amazing typist... and you had RSI and arthritis.

Picture
Look at this! How could it not be anything but brilliant?
But when a program like this was being typed in, where did it go? The answer was in to memory, or RAM as it's called. Any computer has to have a place where it can put things when it's working on them. This is exactly the same as you or I when we do any kind of work - we need a work space. In school you'd be pretty stuck if you walked in to a classroom with no tables and the teacher asked you to start writing in your books.
 

RAM

PictureAlan Sugar in the 1980's would've integrated a cassette deck in your granny given half a chance.
If you want the short version, then the definition of RAM is:

A temporary area of storage for programs and data that are currently being used.

But there's more you need to know:

RAM is volatile, meaning that when you turn the power off whatever is stored there will be lost.

So what kinds of things would you expect to see stored in RAM? Well, if you're using it, then it's in RAM. Some examples:
  • Parts of the operating system
  • Any programs you are currently using, e.g. a web browser, word processor, music player, social media app
  • Any data you have not yet saved - for example, the work you have typed in to a new Word document.

When you open a program or tap on an app icon on your phone:
  • The program is copied from storage to RAM
  • Any data created whilst using the program is stored in RAM (things you type in for example)
  • When you close the program, any changes should be saved to storage again
  • The area of RAM used by the program is then marked as empty or erased.

The fact that RAM is volatile (use this key word in your exam answers always) has two implications:
  1. Anything stored there will be erased if you turn the power off, shut down or restart your computer or even if there is a short power cut.
  2. If a computer does not have any kind of secondary storage, then your computer cannot store or "remember" anything when the power is off

This explains why it's so depressing when a program crashes or if our computer randomly restarts for some reason. If this happens then we usually lose what we were working on. Why? Because whatever we work on is stored in RAM and until we click "save" it is not safe! Anything stored in RAM runs the risk of being lost if there is a program crash or loss of power.

So, you must surely ask the question (if your intelligence circuits haven't melted yet) "If RAM can't store anything without power and it can so easily lose our work... why do we use it?!"

Excellent question, I'm so glad you asked!

The answer is that RAM is fairly fast in computing terms. As a ball park you can imagine that RAM runs between 1/2 and 3/4 the speed that the processor does. This means it's fairly handy at feeding the processor instructions at a rate which is reasonable and means it doesn't sit there idle, doing nothing whilst waiting for program instructions to arrive. 

Modern RAM is very fast. DDR 4 RAM is currently clocked at over 2Ghz, but even this cannot keep up completely with modern processors, but it's "good enough."

The need for RAM

​So we know that RAM is very fast, but not quite CPU speed. But we still haven't answered why we need it. The answer is that if we had computers with no RAM at all and just relied on storage, they would be hideously slow.

I cannot begin to tell you how slow.

Even the most super charged SSD drive is, to a CPU, the equivalent of a one legged man with heart trouble trying to chase after Usain Bolt. He'd have time to go for his post race massage, have a nice cup of tea, do a few interviews and play a game or two of Rocket League before the second man crossed the line.

To get an idea of how bad this would be, I often refer to this article:

https://blog.codinghorror.com/the-infinite-space-between-words/

and particularly this table (the guy that wrote the page actually took it from a particularly mind numbing book, saving you and I the pain of ever having to read it):

Picture
There's a lot to take in from that table but we only need to look at three things:
  • 1 CPU cycle - 1s
  • Main Memory Access (RAM) - 6 mins
  • Solid State I/O - 2-6 days

Lets not even bother looking at "rotational disk" which to you and I is a hard drive. Most computers now, and in the future will only, use an SSD.

So what does this mean? Well to understand the difference in speed, we pretend that one Fetch, Decode, Execute cycle takes only 1 second. If 1 CPU cycle takes 1 second, then to read some instructions or data from RAM takes the equivalent of 6 minutes.

Stop and think for a minute - if it took me 6 minutes to answer a question you asked in class you'd be bored wouldn't you? This explains exactly why we need cache inside a CPU.

But this perfectly illustrates why we need RAM so badly. Although it might take "6 minutes" to access RAM, the fastest storage we have today, a solid state drive, would take between 2 to 6 days.

6 days!

Now you should have a clear understanding of why, even though RAM is volatile, we still need it. If we didn't have RAM, basically computers would be too slow to use.
 

ROM

Picture
I'd be surprised if you haven't seen a screen like the one above, or at least one that's very similar, so what is it?

This text and information is all output from something called the BIOS, which stands for Basic Input Output System. This is, as everything that runs on a computer is, software. It's software that most people don't even notice or pay any attention to (why would most people?) but it is the single most important piece of software in any computer. Without a BIOS, your computer would do absolutely nothing when you turn it on.

If we think about it, we've gone on and on about what software is and the fact that the CPU, from the moment you turn the power on, starts fetching, decoding and executing instructions. We also know that the CPU fetches these instructions from RAM, but when we turn the power off, because RAM is volatile, the contents is empty or lost.

So, when we turn the power on, and RAM is empty... where does the CPU get the instructions from to start the computer up?! The answer, of course, is from the BIOS which is stored in a special kind of memory called ROM.
​

Picture
BIOS has largely been replaced by UEFI these days which is far more intuitive and fully featured, however their purpose is still the same
ROM stands for Read Only Memory. This means:
  • The contents can be looked at or copied by the system but NOT changed
  • You cannot "save" anything to ROM
  • It is non-volatile, meaning the contents of ROM is NOT lost when the power is turned off

Any computing device needs some form of ROM which will hold the software that makes that device work, without it there would be nothing for the CPU to do when the power is turned on. This software can be called:
  • BIOS (Basic Input Output System)
  • UEFI (Unified, Extensible Firmware Interface) - the new version of BIOS for computers
  • Firmware - any software which is designed to enable a device to turn on and handle the functions of that device

When a device is turned on, the contents of ROM will be copied to RAM and the CPU will know to look at a certain address in memory to find and execute its first instructions. Once the firmware/bios has done it's job it can hand over control of the device to other software such as an operating system.

It is important to be really clear in your exam answers:
  • You need ROM to hold the software that makes a device work, such as BIOS or UEFI.
  • You cannot change the contents of ROM.
 

RAM and ROM - Difference

A really common exam question is to ask what the difference is between ROM and RAM. The answer is... everything! The only similarity between ROM and RAM is that they are both forms of storage.

When answering a question like this, it's essential you do two things:
  • Use the word "whereas" in your answer. This will force you to structure your answer and ensure you address both components.
  • Do not shorten your answers or make presumptions. For example, don't write "ROM is non volatile where as RAM isn't." You have to be explicit - "RAM is volatile." See the difference?

To the point, then, what would you write in an exam for this question?
  1. RAM is volatile whereas ROM is non-volatile
  2. The contents of RAM is lost/cleared when the power is off, whereas the contents of ROM will be preserved/unchanged
  3. ROM is read only meaning it cannot be changed, whereas the contents of RAM can be changed
  4. RAM holds open, running programs such as the operating system, whereas ROM holds the code which the system needs to start up, such as the BIOS

That should sort you right out.
 

Performance

Picture
A desk, like RAM, is an example of a temporary working space. Imagine if your desk looked like the one in the picture above.

If you think of each item on the desk as a separate task, as we add new tasks (objects) to the desk, it gets more and more full. As it gets full, it takes us longer to find space for things or, worse, we have to re-arrange the contents of the desk to find a space to use. Eventually, as our desk is quite small, we will run out of space completely and no amount of moving or tidying will improve the situation.

Once the desk is totally full, to do something new we have to do the following:
  • Put something away
  • Make a space for the new task
  • Put the new task on the desk

This obviously takes time.

​How can you improve this situation?
Picture
Simple! Get a bigger desk! More space means more room to spread your tasks around and you can put more things on a larger desk. It's fairly obvious isn't it?

What on earth has this got to do with RAM?

Everything. 

The RAM in a computer is a fixed size. In most machines these days that's around 4-8Gb of space. This sounds like a lot, but right now I have the following open on my laptop (so it's in RAM):
  • Chrome
  • Outlook
  • File Explorer
  • Powerpoint

I am currently using 5.7GB of RAM and I'm not actually doing a great deal - none of those applications are particularly stressful on the machine I'm using. 

As you should see, then, it's actually quite easy or feasible to run out of RAM. This is a real problem. If you haven't read all of this page, scroll up and read about the speed difference between RAM and Secondary Storage.

When a computer runs out of memory, it will slow down significantly. Years ago when computers had 16mb of RAM or so, you'd notice this all the time, these days it's less likely you will run out of memory but it still happens and the consequences are the same - massive slow down. Why is this?

The operating system doesn't want to say no to you, so when you ask it to open another program that doesn't fit into RAM, then it will start to use secondary storage as RAM to fulfil your request. This is called "Virtual Memory" and we will discuss it in more detail in the next section.

What we learn from this is simple:
  • The more RAM a system has, the more programs and data can be open at any one time without losing any performance or slowing the system down.
  • More RAM means you don't need to use virtual memory, which is slow
  • Running out of RAM has a severe performance impact on a machine, so small amounts of RAM are a bad idea in most computers.

But be careful because...
  • You will NOT gain any performance increase if you were not running out of RAM in the first place. E.g. you had 16GB of RAM, only really used 8GB and then installed 32GB of RAM in your system, there would be no increase in performance.
 

Virtual Memory

Picture
Here's another diagram I plagiarised from Google Images...
Computers have a fixed amount of RAM and it used to be the case that when your computer ran out of memory, that was it. It literally wouldn't let you do any more. This was clearly quite a barrier to working as programs and data sets got larger and larger. Operating systems developed to use a system to get round this problem called "Virtual Memory" and it is a real compromise between convenience and performance (speed).

Secondary storage (i.e. a hard drive or solid state drive) is usually very, very large. Therefore, we can create a large file in secondary storage called a "swap file" which the operating system pretends is more RAM. When the main system RAM fills up, we can then start moving things out of RAM and in to the swap file to make room for new programs or more data. By doing this, we don't stop the user doing more things when they have run out of memory.

The process works like this:
  1. Programs are opened and RAM fills up
  2. RAM is full
  3. The user opens a program or more data is created/loaded
  4. The operating system looks at the data in RAM, which is split into "pages" like a book.
  5. The pages that are either not being used at present or are being used the least are copied in to the swap file
  6. The new program/data can then move in to the space created in RAM.
  7. If pages from the swap file are needed, the operating system can again swap some other pages out and move these pages back in to RAM to be used.

The advantage of a swap file is:
  • The computer should continue to work when physical RAM is full (use the term "physical RAM" in your exam answers)
  • It enables the computer to work on far larger amounts of data without the user needing to install more physical RAM

The big disadvantage is:
  • Clearly that it is SLOW because storage is far, far slower than physical RAM
  • It is also slow because it takes time to move pages from physical RAM to the swap file.
 

Types of Memory

So far you have covered three types of memory:
  • RAM
  • ROM
  • Cache

There is also a fourth kind of memory that you need to know about:
  • Flash or "solid state" memory chips

Flash memory is a special kind of memory:
  • it is non-volatile
  • it can be randomly accessed (just like RAM)
  • it is very fast, compared to other kinds of storage (such as HDD)
  • it can be used as secondary storage because it is non-volatile
  • it requires very little power to work - great for portable devices
  • it is physically very small - great for portable devices!

You find flash memory everywhere:
  • USB Memory sticks
  • Memory Cards
  • Mobile phones
  • Tablets
  • SSD's (Solid State Drives)

You need to be able to discuss these types of memory, addressing the following key points:
  • Speed - how fast is it, how fast can the CPU access data/instructions?
  • Size - how much of it is there normally in a system in Mb or Gb
  • Volatility - Will the contents be lost when the power goes off?
  • Use - What would you find in this kind of memory?
  • Advantages and Disadvantages

The table below summarises these points, make use of it when you are answering any questions on memory, but in particular on long answer questions.
 
Picture
Powered by Create your own unique website with customizable templates.
  • Mr Davidson's Blog
  • Twitter
  • A Level CS
    • A Level Exam Technique
    • Lessons
    • Unit 3 - Coursework Guidance
  • OLD GCSE CS - J276
    • All GCSE Questions
    • GCSE Exam Technique
    • Lessons
    • Glossary of Terms
    • Unit 1 Revision >
      • 1.1 - Systems Architecture
      • 1.2 - Memory
      • 1.3 - Storage
      • 1.4 - Wired and Wireless Networks
      • 1.5 - Topologies, Protocols and Layers
      • 1.6 - System Security
      • 1.7 - Systems Software
      • 1.8 - Ethics and Law
    • Unit 2 Revision >
      • 2.1 - Computational Thinking
      • 2.1 - Searching and Sorting Algorithms
      • 2.1 and 2.2 - Writing Algorithms/Programming Techniques
      • 2.2 - SQL and Database Structure
      • 2.3. Robust Code
      • 2.4. Logic
      • 2.5. Translators and Facilities
      • 2.6. Data Representation
  • NEW GCSE CS - J277
    • Glossary of Terms
    • Exam Technique
    • Lessons >
      • Unit 1 - Computer Systems
  • GCSE Business - J204
    • Lessons >
      • Unit 1 - Business Activity, Marketing and People
      • Unit 2 - Operations, Finance and Influences
    • Exam Technique
  • Contact