Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is sizeof(pointer) the same as processor's native word size?

Say, is sizeof(void*) the same as the size processor can atomically access per instruction?

For example, 32-bit processor can read aligned 4 bytes atomically, 64-bit processor can read aligned 8 bytes atomically. While, if it's a 32-bit OS on 64-bit hardware, the atomic access size fall back to 4 bytes.

Note by "atomic access" I mean it fetches as a whole, a counterexample would be 32-bit OS would need to fetch uint64_t two-pass.

like image 453
PkDrew Avatar asked Oct 11 '25 12:10

PkDrew


1 Answers

With modern processors this is generally the case, but the language does not guarantee it.

For example, on old x86 processors running in 16-bit real mode, you could have 32 (or even 48-bit pointers, but loading a 32-bit value still required two memory accesses.

like image 198
SoronelHaetir Avatar answered Oct 14 '25 05:10

SoronelHaetir