r/AskComputerScience • • Apr 19 '21

Whats the difference between RAM and cache?

I’m struggling to understand what a RAM is, looked up and it really sounds like what the cache does im confused

34 Upvotes

31 comments sorted by

42

u/jhaluska Apr 19 '21

They're very similar. Cache is a type of memory. It's faster but smaller. It contains a copy of a portion of the larger RAM. CPUs read and write to the cache to avoid hitting the slower RAM. This allows the computer to run faster.

Modern computers have multiple caches for the CPU, labeled L1, L2 and L3. L1 is smallest and fastest. L3 and largest and slowest.

A lot of the speed restrictions are literally the speed of light! So think about the further away you go from a point, light takes longer to reach and return but it covers more and more volume!

4

u/z3ny4tta-b0i Apr 19 '21

Oh wow thanks!

2

u/bill_klondike Apr 19 '21

And don’t forget about the fastest and smallest of the memory hierarchy: registers.

3

u/AxelTheRabbit Apr 19 '21

Maybe I'm wrong but L stand for latency and has nothing to do with light.

We don't use light in CPUs but electrons because there are quantum and size issues with light as far as I know.

I also quickly read the wikipedia page and I don't see anything about the light speed. https://en.wikipedia.org/wiki/CPU_cache

5

u/ICantMakeNames Apr 19 '21

The speed of light isn't a cache-specific problem in computers. Its a general problem, in that it limits how fast signals can be transferred through a medium. By having caches physically closer, they are faster, because distance matters at the speeds that signals are sent through CPUs. Accessing RAM takes longer for several reasons, one of which is it literally takes many clock cycles for the signal to reach it.

https://www.scientificamerican.com/article/computers-are-becoming-fa/

2

u/jhaluska Apr 20 '21

The L stands for Level. I never said L stood for light.

1

u/S-S-R Apr 19 '21

A lot of the speed restrictions are literally the speed of light!

I don't know who keeps telling you guys this, but this is not true.

7

u/ICantMakeNames Apr 19 '21

Care to explain? It was my understanding that electricity travels at a significant portion of the speed of light (i.e. we cannot make electricity travel any faster because of the speed of light), and that CPU clock cycles are so fast, that CPU components need to be physically closer to actually make use of the faster clock cycle (too far away, and it takes longer for the signal to reach the component than a clock cycle takes)

1

u/AxelTheRabbit Apr 19 '21 edited Apr 19 '21

it's not about the speed of the light. it's about the speed of electrons in a mean of transport, which is not even close to the light speed. the rest is right, they are designed as close as possible to reduce latency.

10

u/ICantMakeNames Apr 19 '21

https://www.scientificamerican.com/article/computers-are-becoming-fa/

(emphasis mine)

"The speed of computers is limited by how fast they can move information from where it is now to where it has to go next and by how fast that information can be processed once it gets here. An electronic computer computes by moving electrons around, so the physical restrictions of an electron moving through matter determine how fast such computers can run. It is important to realize, however, that information can move about a computer much faster than the electrons themselves. Consider a garden hose: When you turn on the faucet, how long does it take for water to come out the other end? If the hose is empty, then the amount of time is equal to the length of the hose divided by the velocity at which water flows down the hose. If the hose is full, then the amount of time it takes for water to emerge is the length of the hose divided by the velocity at which an impulse propagates down the hose, a velocity approximately equal to the speed of sound in water.

"The wires in an electronic computer are like full hoses: they are already packed with electrons. Signals pass down the wires at the speed of light in metal, approximately half the speed of light in vacuum. The transistorized switches that perform the information processing in a conventional computer are like empty hoses: when they switch, electrons have to move from one side of the transistor to the other. The 'clock rate' of a computer is then limited by the maximum length that signals have to travel divided by the speed of light in the wires and by the size of transistors divided by the speed of electrons in silicon. In current computers, these numbers are on the order of trillionths of a second, considerably shorter than the actual clock times of billionths of a second. The computer can be made faster by the simple expedient of decreasing its size. Better techniques for miniaturization have been for many years, and still are, the most important approach to speeding up computers.

-1

u/S-S-R Apr 19 '21

It's commonly taught that it's bounded by the speed of light, but when people actually mean it's bounded by a constant and the speed of light. i.e nc where n < 1. In the same way my car is bounded by the speed of light and n where n = 0.000000093.

In other words this isn't very useful and often misleading, I've had many IT/compsci people argue that communication happens at c but that's not even remotely true.

3

u/ICantMakeNames Apr 19 '21

From what I read, its not fair to compare the speed of an electronic signal to a car. You can change the speed of the car by adding more energy to it, but the speed of a signal in a particular medium is a constant, and is effectively "the speed of light" in that medium. You're correct that it is not the speed of light in a vacuum, but I don't think that's not an important distinction to make.

2

u/mplang Apr 19 '21

The theoretical upper bound of signal propagation is the speed of light. Even if it is restricted by other things, the speed of information travel is nonetheless a function of the speed of light and distance traveled.

-1

u/oligIsWorking Apr 19 '21

So really the only relevance, is that the speed of light is the constant upper bound. So it is as relevant to electronic signals as it is for measuring anything moving through time and space.

2

u/mplang Apr 19 '21 edited Apr 20 '21

No. First, in this context, "light" refers to all electromagnetic radiation (and therefore applies directly to electricity). Second, "the speed of light" is not constant -- light propagates at different velocities through different media (hence refraction). But it's still this "raw" speed that's the primary component of how fast the signal moves.

-1

u/Igotz80HDnImWinning Apr 19 '21

Now are we talking speed of light in a vacuum or in a liquid or solid? Is it an unladen swallow?

10

u/lifeHacker42 Apr 19 '21 edited Apr 19 '21

Lookup "the memory hierarchy" that should help you understand all this.

It's a fundamental thing to understand when it comes to memory so make sure you get it before moving forward. If you need any further help explaining it if Google isn't clear enough drop me a message I'll happily help but Google should be enough as there are some really clear explanations there

Edit: typo and additional information

9

u/msiekkinen Apr 19 '21

To add to what others have said the memory you generally call RAM is DRAM, memory used for on die CPU caches are generally SRAM. SRAM is faster, but more expensive, which is why you don't see multi gigabyte modules of system RAM using that.

2

u/Bottled_Void Apr 19 '21

I'm not sure the distinction between DRAM and SRAM is the important point. There are some types of SRAM which aren't used for cache and aren't faster.

1

u/msiekkinen Apr 19 '21

Seemed important enough of a distinction to be in opening of the wiki article I linked.

7

u/spaztheannoyingkitty Apr 19 '21

To add to what others have said, a cache is also a generic term for keeping friendly accessed information quickly at hand for fast access: https://en.m.wikipedia.org/wiki/Cache_(computing)

12

u/Knaapje Apr 19 '21

To add to what others have said a ram is also a siege engine used in medieval warfare, used to breach keep doors and other fortified structures. Their use as siege engines quickly declined with the advance of gunpowder and other siege engines, such as the trebuchet, the superior siege engine.

7

u/FoxchildWasTaken Apr 19 '21

Oh cache is where they stored weapons and such, right?

3

u/Knaapje Apr 19 '21

Correct, there's different levels of caches too. Level 1 caches provide quickest access, since it's on the ground floor. Level 2 takes a bit longer, and so on.

2

u/not-just-yeti Apr 19 '21 edited Apr 19 '21

price vs. speed

[I mean, the top post is a great answer to what OP was after; but once that is understood, the whole memory-hierarchy is largely one big continuum of trading off the above two.]

2

u/oligIsWorking Apr 19 '21

A nice way of thinking about it I just thought of is this:

End user uses Storage memory (HDD/SSD)

Developer uses/programmes RAM

CPU Architect uses the cache.

2

u/[deleted] Apr 20 '21

Just to add some insight, cache is a very special memory because it's closer to the processor, it uses probability inference to store the data, it's used to store those chunks of bytes that the processor access the most.

-8

u/CuriousCerberus Apr 19 '21

RAM is the physical memory chips you install in your computer on the motherboard. Cache can be virtual memory used by the operating system and you can change the size of it in system settings and is a temporary location on the hard drive. That's why the size of it can be changed because it uses the hard drive space. RAM is a static size depending on the size and number of chips installed in the computer.

3

u/Bottled_Void Apr 19 '21

I believe they're asking about the l1 and l2 cache on the processor, not virtual memory.