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)
293
Upvotes
219
u/ZirePhiinix Jul 13 '23
I thought it was an article, but it is a freaking 114 page research paper...
11
u/avoere Jul 13 '23
When is it relevant for a programmer to know the difference between SRAM and DRAM? Yes, knowing about latency (and caches) is important, but the actual technology used is only relevant to digital circuit designers.
2
u/ad81923 Jul 14 '23
This reminds me of https://samwho.dev/memory-allocation/ which is pleasant and fun to read!
68
u/TheDevilsAdvokaat Jul 13 '23
From the article:
225
u/inlimbo57 Jul 13 '23
Unpopular opinion perhaps: for 99% of programmers, this is not relevant knowledge at all
11
u/obQQoV Jul 13 '23
Does this apply to embedded systems?
65
u/Unlikely_Response125 Jul 13 '23
I used to know this but I forgot. My memory isn’t great
45
u/StickiStickman Jul 13 '23
Almost no programmer needs to know even 10% of this, probably not even 1%
18
u/mkirisame Jul 13 '23
I read this before, should be named what a small subset of programmer should know about memory.
8
u/AppearanceHeavy6724 Jul 13 '23
There is a lot resentment to this idea from higher level language programmers. I have hard time understanding why. I personally program both in high and low-level languages, and I am sure knowing the knowledge of low-level stuff did indeed help me to write better say Python code, yet I cannot bring up any concrete examples, cause I do not remember every small optimization I did in my life.
1
u/[deleted] Jul 15 '23
Given the constant changes in technology, it seems normal to me that a programmer should be unaware of how memory works at hardware level. It's up to the compiler to optimize.
On the other hand, I wonder what the impact for programmers would be of a new architecture where there's no longer any difference between RAM and disk (could we do that with ReRAM?).
3
u/zippy72 Jul 13 '23
Is there an epub version of this? I'm not fond of trying to read two columns of 3pt FlySpeck on my phone
10
u/[deleted] Jul 13 '23 edited Jul 13 '23
The only thing I want all the programmers on my team to know is the difference between stack and heap memory. It's shocking how often I have to re-explain that to some fresh from college.
The senior programmers are also expected to be aware about the CPU cache and how to organize large data structures so that you get as many cache hits as possible (if perf matters) and how the C# volatile keyword greatly matters when you start writing multi-threaded code.
11
u/voteyesatonefive Jul 13 '23
Love to see people pushing for ignorance. /s
Having a basic understanding of the systems you use directory and indirectly, and being able to find more specific information is important. I would guess that most programmers develop on systems where the content of this paper is relevant.
4
u/FallFrom Jul 13 '23
"I don't need to know any of that! Hmm... why this code editor takes 30 seconds to start and eats half of my RAM?"
2
u/[deleted] Jul 13 '23
Having had a go reading this, it starts off incredibly dense, and then gets much easier offering a bunch of practical advice and then it gets domain specific. For a first reading, give up on the DRAM stuff, read the following few chapters, and then skim the rest of it for things relevant to you.
2
u/Havarem Jul 13 '23
Is there a new version of this? It is very well put but as on 2023 we see the rise of the specialized computing units such as video encoder/decoder, tensor, neurotrophic, optical, etc. I’ve also seen commodity motherboard equipped with FPGA between CPU’s, PCIe and/or memory.
2
u/ucblockhead Jul 13 '23 edited Mar 08 '24
If in the end the drunk ethnographic canard run up into Taylor Swiftly prognostication then let's all party in the short bus. We all no that two plus two equals five or is it seven like the square root of 64. Who knows as long as Torrent takes you to Ranni so you can give feedback on the phone tree. Let's enter the following python code the reverse a binary tree
def make_tree(node1, node): """ reverse an binary tree in an idempotent way recursively""" tmp node = node.nextg node1 = node1.next.next return node
As James Watts said, a sphere is an infinite plane powered on two cylinders, but that rat bastard needs to go solar for zero calorie emissions because you, my son, are fat, a porker, an anorexic sunbeam of a boy. Let's work on this together. Is Monday good, because if it's good for you it's fine by me, we can cut it up in retail where financial derivatives ate their lunch for breakfast. All hail the Biden, who Trumps plausible deniability for keeping our children safe from legal emigrants to Canadian labor camps.
Quo Vadis Mea Culpa. Vidi Vici Vini as the rabbit said to the scorpion he carried on his back over the stream of consciously rambling in the Confusion manner.
2
u/This_Anxiety_639 Jul 14 '23
If you are not writing device drivers in assembly or C, you probably don't need to know this stuff, although it is interesting. The difference between DRAM and SRAM was new to me, and I feel richer for having learned it. But as a J2EE/Angular developer, it's not likely to affect my day-to-day.
6
u/obsCUR Jul 13 '23
Queue gc people noon needs to know about memory
1
u/Stunning-Plant4368 Jul 13 '23
Very cool, thank you!
EDIT: Just began reading. Actually, I love this!! I'm a psychologist considering transitioning into programming. This is exactly what I'm interested in. Thank you!!!
1
u/rust_devx Jul 13 '23
Anyone have an alternative resource that isn't this dense and like 100+ pages?
-1
u/turbo_dude Jul 13 '23
Those people who needed to know this would already know it and those who don't don't.
-2
u/akarost Jul 13 '23
One thing every programmer should know about memory, you can always add more.
-2
u/st4rdr0id Jul 13 '23
Programmers don't need to know any of this. Maybe for a CE degree some of the material is adequate.
-86
u/wicklowdave Jul 13 '23 edited Jul 13 '23
Lol I'm not reading that. I'm a programmer and everything I need to know about memory is handled by GC. Just be careful to remove delagste assignments when you're done with them. That one got me before.
edit oofffff I seem to have rustled a few jimmies here