r/programming • u/TheFlyingCoderr • Jul 13 '23
What Every Programmer Should Know About Memory
https://people.freebsd.org/~lstewart/articles/cpumemory.pdfThis resource is starting to get a bit older. But it's such a good resource for learning about memory.
Hope you like it (it's a pdf)
296
Upvotes
View all comments
Show parent comment
89
u/Brian Jul 13 '23
Is it?
How much misuse do you think a web developer will commit because they don't know the difference between NUMA and UMA? Or that RAM cells usually have 6 transistors? Or that RAM has a refresh cycle every 64 ms, or the difference between full and set-associative caches?
But that's the thing - no farmer knows how farming actually works. They stop at a level of abstraction that makes sense for them: the detailed biology of how the bacteria in a cow's gut breaks down their grass is important, sure, but not usually something they have to care about themselves - they just care that that bacteria is there and doing its job.
At some level, your understanding of how something "actually works" is only as deep as the deepest abstraction you use, and no-one's abstractions go all the way down. Few programmers understand the quantum mechanics that let modern transistors work, for instance, and unless you're working in chip fab, it probably wouldn't help you if you did. Now, there are advantages to knowing a few abstractions lower than what you're building on: abstractions do tend to be leaky, and understanding the underlying mechanism can help. But that web programmer won't make any fundamental errors on par with a farmer harvesting at the wrong time just because they don't know that cache prefetching won't cross page boundaries, for the same reason the farmer won't because they don't know the the metabolic full cycle of gut-bacteria - it's too much below the abstractions they're working with to matter.
Which is not to say that other programmers won't benefit from knowing it - but only really if they're working at a lower level: an OS kernel say, or maybe detailed benchmarking where RAM refresh could make a difference. But I think most programmers only really need to know some basics (Roughly what virtual memory does, caches are faster than RAM - so pack stuff together). Even then, at higher levels of abstraction you can get away without it.