Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Integer memory storage
#9
(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.
Reply


Messages In This Thread
Integer memory storage - by bobalooie - 11-11-2023, 11:12 PM
RE: Integer memory storage - by bplus - 11-11-2023, 11:45 PM
RE: Integer memory storage - by SMcNeill - 11-12-2023, 12:49 AM
RE: Integer memory storage - by bobalooie - 11-12-2023, 01:29 AM
RE: Integer memory storage - by mnrvovrfc - 11-12-2023, 01:05 AM
RE: Integer memory storage - by SMcNeill - 11-12-2023, 01:19 AM
RE: Integer memory storage - by DSMan195276 - 11-13-2023, 05:05 AM
RE: Integer memory storage - by bobalooie - 11-14-2023, 04:13 PM
RE: Integer memory storage - by DSMan195276 - 11-14-2023, 09:04 PM



Users browsing this thread: 2 Guest(s)