3 ms·
As a general point, it's easy to forget all the layers. If you learn C, you feel close to the metal. I have an array. It is contiguous bytes in RAM. I've got t
by 6cxs2hd6 13y ago
As a general point, it's easy to forget all the layers.
If you learn C, you feel close to the metal. I have an array. It is contiguous bytes in RAM. I've got the power!
Well maybe.
The array might be contiguous virtual memory, but backed by disjoint blocks of physical memory.
Then there's cache. In front of ... another cache.
At least with C you're closeER to the metal.
- octo_t 13y agoAnd some of your code is in the instruction cache and some isn't - meaning a sudden context[1] switch has to read a lot of code from memory which is slow(ish) [1] - not a thread switch (although that would be as costly), but an if-statement in a while loop changing from false to true etc.
- pbsd 13y agoUnless it's a friggin' gigantic loop, instruction cache miss will usually not be the issue there; branch misprediction will. Instruction cache misses are particularly problematic in codebases with many virtual function calls (or plain function pointers in C), which can't be easily prefetched ahead of time.
- deleted 13y ago[deleted]
- octo_t 13y agoI'll admit that branch misprediction will also screw you over, large event loops are sometimes large enough to escape the instruction cache (especially with function inlining)