11-14-2023, 09:04 PM
(11-14-2023, 04:13 PM)bobalooie Wrote: So, if I have a program that uses two _BIT variables as flags, I suppose each variable would occupy its own cacheline in memory.No, likely the opposite. Very generally speaking, your variables will get packed into memory one after another (subject to any alignment requirements). If you declare 8 LONG variables in a row , they will likely end up as one 32-byte chunk of data in memory (for arrays this is always the case). It's not quite that simple due to some stuff QB64 does, but that's roughly accurate.
The CPU then reads from RAM in cacheline sized chunks, so all the variables within those 32-byte or 64-byte ranges get read together. If your LONGs are next to each other, then it will read 8 or 16 of them in one go (each LONG is 4-bytes, so 8 of them is 32-bytes). Whether that actually happens depends on which cachelines those individual variables fall into though, as the cachelines start and end at defined intervals. So while every LONG will be in only one cacheline (due to its alignment), you might end up with 3 LONGs at the end of one cacheline, and then 5 LONGs at the start of the next cacheline.
Ex. The cachelines are bytes 0-31, 32-63, 64-95, 96-127, etc. If you declare 2 LONG variables, they might get placed at bytes 8-11 and 12-15, and that would mean they're both in the first cacheline and get read from RAM together. It's also possible they will get placed at 60-63 and 64-67, in that situation they're still next to eachother but in different cachelines, and thus wouldn't be read from memory at the same time.