3 ms·
Sure. Suppose you have an 8 byte address space. You'll need 3 bits to address them (0,1,..6,7). But, if the only objects you store must fall on a 4 byte boundar
by MichaelGG 11y ago
Sure. Suppose you have an 8 byte address space. You'll need 3 bits to address them (0,1,..6,7). But, if the only objects you store must fall on a 4 byte boundary, there's only two valid addresses: 0 and 4. You can represent that with one bit, just multiply the value by 4 (0->0, 1->4).
Same for any other size. Got 32 bit address space, 4GB? Well with 4 byte alignment, you shave off two bits, just multiply every pointer by 4 (left shift it by 2).
With the two highest bits, you're free to encode other information for whatever little things you need to keep track of in the runtime.
The JVM already does this on x64 so that instead of 8 byte pointers, they're only 4 bytes. But alignment bumps up the range from 4 to 16(?) GB - or something like that? Compresssed object pointers I think is the name if you wanna look up more.