r/programming • • Jul 13 '23

What Every Programmer Should Know About Memory

https://people.freebsd.org/~lstewart/articles/cpumemory.pdf

This 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

156 comments sorted by

View all comments

Show parent comment

27

u/Randolpho Jul 13 '23

Agreed.

This is a good paper for non CS programmers who are curious about the inner workings of the black box they manipulate to read, even though it’s 15 years out of date. Programmers who came up through a CS degree but turned to general software careers already know the basics of what’s touched on here, if not always some of the details.

But for most people manipulating that black box to do general purpose software like web apps or mobile apps or even the now gauche desktop UI, any of the details listed here are only important to software subsystems whose APIs those modern programmers use. Indeed, it’s far more likely that modern programmers are several layers above components where the details of this paper matter.

And for the people who actually need to know stuff like this, the people writing drivers and low level OS subsystems… those people already know more than this paper even manages to convey.

That said I still encourage non-CS and even CS background programmers to consume this paper. It doesn’t matter directly, but sometimes context is helpful. And who knows? Maybe it’ll spark interest in a hobby or career change.

11

u/siemenology Jul 13 '23

Indeed, it’s far more likely that modern programmers are several layers above components where the details of this paper matter.

Yeah it's kind of hard to write code that takes advantage of caching and prefetches and stuff when you are writing in a high level language that runs on a language-specific VM. Where you have zero control over the assembly generated, where and how it is stored, when and how memory is allocated, where and how your data is stored, etc etc. You are better off reading performant-coding guides for your language. The things they tell you to do may make your code more performant because the code generated will be better optimized for CPU caches, but that detail doesn't actually matter to you as a programmer -- it could just as easily improve performance for reasons that are entirely specific to the language and VM, that have nothing to do with the CPU and memory.

2

u/Full-Spectral Jul 14 '23

Ruby on Cache Lines

1

u/Randolpho Jul 13 '23

Exactly.

1

u/master_mansplainer Jul 14 '23

Yep, it’s practically impossible, you’re going to have data scattered around and non sequential, cache misses etc unless you’re basically abandoning mosy features and all managed aspects of the language.

3

u/boss14420 Jul 14 '23

even though it’s 15 years out of date

Consider DRAM latency hasn't get improved much in the last 3 decades, this article is not too out of date.