4 ms·
No. On 64bit machines, a 32bit index saves you significant memory, and if you can use a 16bit... even more. These savings matter a lot in some domains of comp
by cjhanks 8y ago
No. On 64bit machines, a 32bit index saves you significant memory, and if you can use a 16bit... even more.
These savings matter a lot in some domains of computing.
- doomrobo 8y agoAn index into any std data structure has type usize, though, and usize is 64 bits on a 64 bit machine.
- dbaupp 8y agoThey don't have to be stored as a usize. This is slightly annoying because it may add casts, but not if one already has a newtype wrapper around the integers: the type stored in the wrapper could be a u32, with the conversions to usize hidden by the indexing APIs.
- cjhanks 8y ago2 cycles or so, I think. In my experience, this cost is usually overwhelmed by the inherent (to this class of algorithms) cache misses.
- dbaupp 8y ago2 cycles for a 32-bit to 64-bit extension? I don't think that makes sense: for instance, on x86-64, there's no cast necessary, just use the %rax register instead of the %eax one (plus, memory addressing works fine with 32 bit registers directly). I believe the same is true of AArch64 (64-bit ARM) with the 32-bit register W0 being the bottom half of the 64-bit register X0.
- cjhanks 8y agoYeah, your intuition seems correct to me. I wonder if I was thinking about 64 to 32 signed, or if just didn't know.