Key takeaways
Think of RAM as your desk: it holds the data a program is currently working with. An SSD or hard drive is more like a filing cabinet, keeping data for the long term. Ordinary RAM loses its contents when power is lost. Unsaved changes may disappear, while a copy already saved to storage remains. Data in memory is represented by bits: 0s and 1s. One byte contains 8 bits. In Java, an int holds 32 bits of data, equivalent to 4 bytes. An address tells you where data is; a value tells you what is there. In a contiguous array model with equal-sized elements, an element’s address is calculated as: base address + index × element size. “Random access” does not mean choosing something randomly. Given an index, a program can access an array element without reading every preceding element. In the standard algorithmic model, this takes O(1) time. Consecutive addresses seen by a program do not necessarily correspond to adjacent locations in physical RAM, because programs typically use virtual addresses. A character does not always fit in one byte. In Java, a char is a 2-byte UTF-16 code unit; a single character that a person sees may require multiple code units.

🌐 Languages: English · Tiếng Việt bên dưới

1. RAM is your desk, not your filing cabinet

Imagine preparing a presentation. You take a few documents out of a filing cabinet, open your notebook, and put what you need on your desk. The other documents stay in the cabinet; you don't need everything out at once.

Think of the computer the same way: the SSD or hard drive is the filing cabinet, RAM is the desk, and the CPU is the person doing the work. RAM, short for Random Access Memory, holds working data for quick access by the processor. [1]

Ordinary RAM does not retain its contents without power. Changes held only in RAM can be lost, while saved copies remain on storage. A recovered document doesn't mean RAM remembered it—the application may have saved a copy earlier. [1]

The picture in a diagram

Đang vẽ sơ đồ…

Xem mã sơ đồ
```mermaid
flowchart LR
    S["SSD / HDD<br/>Filing cabinet"]
    R["RAM<br/>Desk"]
    C["CPU<br/>Person doing the work"]

    S -->|"Load data"| R
    R -->|"Read"| C
    C -->|"Write results"| R
    R -->|"Save through the application and OS"| S
```

A simplified model of the roles; caches, registers, and operating-system layers are omitted.


2. What is actually inside memory?

A real desk holds paper, books, and pens. Memory represents data as bits, each with a value of 0 or 1. Picture a tiny switch with just two states: off or on.

Put eight switches together and you have one byte: 1 byte = 8 bits. [2]

For example, the numbers 1,

Sources

  1. Kingston — The difference between memory and storage
  2. NIST — Prefixes for binary multiples
  3. Microsoft Learn — Virtual address spaces
  4. Oracle — Java Language Specification: Primitive Types and Values
  5. Princeton — Arrays
  6. Unicode Consortium — UTF-8, UTF-16, UTF-32 & BOM
Author

Hung Pham

Writing from Hunpeo Labs Journal.

Discussion

Newest first

Loading comments…

Spam checks run automatically. Some comments may be held for review.