2 ms·
The minimum access in modern computers is 1 byte of 8 bits, which means that to losslessly change the value of an 1-bit bool you need three instructions: 1. lo
by mschuster91 2y ago
The minimum access in modern computers is 1 byte of 8 bits, which means that to losslessly change the value of an 1-bit bool you need three instructions:
1. load byte at $address into $register
2. use whatever native instructions there are to change just that single bit in $register - in the worst case you need multiple of them
3. write byte from $register into $address
In contrast, all modern platforms have a single "store immediate (=hardcoded in the bytecode) value" instruction, so it's either two (set register to 0 / 1, write register to RAM) or even one (write value directly to RAM) instruction.
Bit-packing structures (another poster showed an example here in the thread) used to be done pretty much everywhere and you'll notice it if you deal with reverse engineering code even from the Windows 98 era... but in anything more modern it's not needed because computers nowadays have more than 640 KB of RAM [1].
By the way, accessing / modifying small values in large(r) containers is a common problem in computing in general, so if it interests you, you might want to look into "SSD write amplification", "SMR HDD write amplification" or "flash wear leveling".
[1] https://lunduke.locals.com/post/5488507/myth-bill-gates-said-640k-ought-to-be-enough-for-anybody https://lunduke.locals.com/post/5488507/myth-bill-gates-said...