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)

298 Upvotes

156 comments sorted by

View all comments

Show parent comment

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.