What is "Memory" in a Computer?
The term "memory" has multiple meanings when we talk about computers, some of them refer to hardware while other refer to software, for example:
- Memory means RAM memory when talking about buying more memory or needing more memory, which is where data must be loaded into before it can be used by the CPU.
- Memory also means virtual memory when your computer runs out of memory, which is where data is loaded so that a program can use it in a typical operating system.
- Memory can also mean permanent memory, which can be writable, such as hard disks and SSDs, or read-only memory (ROM memory).
Notable Features
In general, memory has a fixed size and is addressable by byte offsets.
If you have a piece of memory that is 8 bytes, you can't add bytes to it or remove bytes from it, because it would be a physical component. You can't just make your hard disk bigger or your RAM chips larger. Consequently, when you create a new file or when something is loaded into the RAM, bytes aren't being added or removed, it's just their values that are getting overwritten.
Similarly, when a file is deleted or something is unloaded from memory, what's actually happening isn't that we are removing or erasing bytes, we're simply saying that those bytes the file occupied can now be used to store the data of another file.
A single byte is 8 bits of data, but it's normally not possible to retrieve a single individual bit from memory, because there are simply too many bits. Instead, the computer retrieves a sequence of bits (a byte or more) at a time.
Consequently, when the computer handles memory, it speaks in terms of byte offsets. I want the 1st byte. I want the 2nd byte. Store this data in the 3rd byte. And so on.
Often, data requires more than 1 byte to be stored. In this case, it's often stored as a contiguous sequence of bytes. Put this data of 4 bytes in the bytes number 33, 34, 35 and 36.
Because programs often require contiguous spaces of memory, this means the computer is rarely able to use all of the memory of the computer, as there will always be tiny unused gaps in them. For example, if you have 4 gigabytes of memory, and somehow only 2 programs running, and one program uses 2 gigabytes of contiguous memory, then you have 2 gigabytes of memory left, but those 2 gigabytes aren't necessarily contiguous.
Imagine three scenarios:
|XX__|
|_XX_|
|__XX|
In the first scenario, we have 2 gigabytes of continuous memory used at the start, which means we have 2 gigabytes of continuous memory left at the end. In the 3rd scenario, it's the same thing but with sides switched. However, in the second scenario, we have some unreserved memory at the start, 2 gigabytes of contiguous memory in the middle, and unreserved memory at the end.
If we needed another 2 gigabytes of memory, we also have it, but if we need 2 gigabytes of contiguous memory, then we wouldn't have it in the 2nd scenario.
Leave a Reply