Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Integer memory storage
#7
(11-12-2023, 01:19 AM)SMcNeill Wrote: On 32-bit OSes, data aligns on 4-byte intervals.  On 64-bit OSes, data aligns on 8-byte intervals.
The key is not the CPU bitness but rather the cacheline size, which is typically 32 bytes or 64 bytes (on modernish CPUs). The CPU reads memory from RAM in cacheline-sized chunks, so if your data is within a single cacheline then it only requires one read. Additionally (on x86), as long as the data is within a single cacheline it doesn't matter what the alignment of the data is, that doesn't impact the speed. Point being, it's good to align your data since it ensures it will always start on a cacheline, but you don't actually need to get more granular than 32 bytes to achieve that.

For inserting padding, the question is more the alignment requirements of the individual types, which are the same on 32-bit vs. 64-bit and typically just the size of the type. Like @mnrvovrfc mentioned though, UDTs don't actually get any padding added, so because of that you can make them significantly more efficient by ensuring their size is a multiple of 32 bytes.
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: 4 Guest(s)