Return to main page
View source or report issues on GitHub

Memory and Storage

Memory in a computer

Every computer has multiple places where data - 0’s and 1’s - can be stored. Each place serves a different purpose.

Secondary Memory

Secondary Memory:star: or secondary storage is the part of a computer where data lives when it’s not being directly used. In most computers this will be a hard drive or solid-state storage. This could also be exterior storage such as CDs, DVDs, USB Flash drives, SD Cards, video game cartridges, and so forth. This memory is slow, but usually cheap (relatively), and is persistent:star:, which means that it will continue to hold data even when power is disconnected. 2.1.5

Primary Memory

The hierarchy of memory
Image credit: https://www.slideshare.net/rahulbandhe/basics-of-semiconductor-memories-presentation

  1. ROM:star: (Read Only Memory) is a tiny piece of medium-fast memory built into the main structure of the computer (but not directly into the main processor chip). It is usually small and contains only the tiny bit of software needed to actually start a computer, before the operating system takes over. If you’ve ever “flashed a firmware update” on your computer, router, or phone, you have edited the ROM. This is the only part of primary memory that is persistent.2.1.2

  2. RAM:star:, or Random Access Memory is the part of the computer where data is stored that is being actively used by running programs. It is generally much smaller than the secondary storage, but much faster. A modern computer might have 16 Gigabytes of RAM, but 500 or more GB of hard disk space, for example. 2.1.2

  3. Cache:star: is an even faster and smaller section of memory that is used by the computer to store things it knows it may need again soon. It is usually directly connected to the computer’s “brain” (CPU), which gives it extreme speed. From the perspective of a programmer, the cache and RAM are essentially interchangeable, but they make a huge difference at the low level; computer processor designers spend lots of time optimizing cache usage, since the cache can be up to 100 times faster than the RAM!. It is very expensive, however, so most computers have less than a gigabyte of cache total, and often significantly less of the fastest level 1 cache.2.1.3

  4. CPU Registers:star: are the smallest, fastest memory, but they are usually considered as part of the CPU architecture. They are used only for values involved in the current operations of the processor. We will discuss them more in Lesson 2.3

As a programmer, we mostly only worry about the persistent storage (which we tend to call the disk or the files) and the RAM (which we tend to call the memory.) The CPU and programming language handle the movement between RAM, cache, and registers for us, while the ROM does its own thing when the computer starts and is otherwise not our concern.

What goes in the memory?

Though the different storage types all works very differently at a physical or chemical level (hard drives use magnets, dvds use lasers, etc), for a programmer it is reasonable to think of memory as holding a giant series of 0’s and 1s. This is another example of an abstraction!4.1.17

Each 0 or 1 is called a bit:star:.2.1.9 By itself, a bit can’t convey a lot of meaning, since there are only two options. But if you combine the 0s and 1s into groups, you can get more interesting combinations. A group of 8 bits is called a byte:star: and provides \(2^8=256\) possible values, from 0000 0000 to 1111 1111.

Given a single byte (or more than one) we can train our programs to interpret it in different ways. For example, the byte 0011 1011 might be interpreted as the integer 59, or the text character a, or the percentage 23.13%, depending on the interpretation instructions we are using. Later in this course we will explore some of these encoding schemes in detail.

Virtual Memory (HL topic)

Occasionally, a computer will completely run out of available cache and RAM to keep track of all of the running programs. In that situation, the operating system, which is the primary software that controls how the computer works, may allow programs to use virtual memory, or swap space, which allows the programs to use space on persistent storage in the same way they might use RAM.

The advantage of this is that the computer can continue to run all of the programs on the computer without causing any sort of error caused by insufficient RAM, and extremely large programs can run even on devices with less RAM.

The disadvantage is that persistent storage solutions are MUCH slower than RAM (often by 50 or 100 times or more!) so the computer will run the programs much more slowly. Faster secondary storage options, such as modern Solid State Drives, are much faster than older drives and make virtual memory more feasible, but RAM is still significantly more efficient.

Study Materials

Check your Understanding

  1. What is the difference between RAM and ROM?

    Click to expand answer

    RAM means Random Access Memory, and it is the section of primary memory that holds the data the computer is using as it works. ROM stands for Read Only Memory, and is the special part of primary memory that holds the important information needed to get the computer started, sometimes called the firmware. Other than their acronym, they have almost nothing in common!

  2. How many bits are in one byte?
    Click to expand answer

    8

  3. What are some types of primary memory?
    Click to expand answer

    ROM, RAM, Cache, and CPU Registers

  4. Why is it important that we have some forms of persistent memory?
    Click to expand one possible answer

    Without persistent memory, the computer would have to start over from scratch every time its power was removed! Things like documents, photos, settings, and so forth require persistent storage to exist in a digital world.

  5. What is the only type of primary memory that is persistent?
    Click to expand answer

    The ROM is persistent; it has to exist between power cycles or else the computer won’t be able to start.

  6. May 2019, problem 15, SL
    A company that provides training for teachers plans to set up a training room in its offices with a network of 15 computers. Each computer is 1 TB of storage and 16 GB of RAM.
    1. Identify two characterists of RAM

    2. State the purpose of persistent storage on the computers.

    Click to expand official IB markscheme
    1. Award [2 max]
      RAM is volatile / contents erased when power is switched off;
      Access speed is fast / faster than hard drive;
      Data / instructions can be read from and written to it / /RAM can be overwritten;
      Size is limited;
    2. Award [1 max]
      To store programs / files / data in a non-volatile device so it isn’t lost;
      Stores more data as is has more capacity;
  7. May 2019, problem 5, HL (HL only!) Outline one advantage and one disadvantage of using virtual memory.

    Click to expand the official IB markscheme

    Award [1] for an advantage, [1] for a disadvange, and [1] EACH for outlines (additional details) 4 marks total

    Potential Advantages

    Allows more applications to run than there is available physical memory; By the use of page/swap files/part of hard disk as primary memory;

    Larger application can run With less real RAM;

    Potential Disadvantages

    Applications run more slowly;
    Uses hard drive memory as primary memory / takes more time to switch between applications;

    When a computer’s virtual memory resources are overused /Reduced amount of hard drive space available for your use;
    programs lock-up/do not run/disk thrashing;

Terms

Bitmoji Books Create flash cards or a quizlet deck with the following words on one side and a quick summary on the other.