I'm programming a 4x4 board game in C using bitboards in a 64-bit machine. I only need 16 bits to implement the board. Should I use:
- uint16_t - to reduce used space?
- uint64_t - if operations are(?) faster with 64-bit integers, should I use them and mask the value with 0xFFFF (bitwise AND) when necessary?
- uint_fast16_t - I just discovered this integer type, but I'm not sure how it works and if I would need a mask too?
I don't know if it helps, but my processor is: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz 1.99 GHz
CodePudding user response:
- If you are looking to save space, use
uint16_t
. - If you are looking to save time, use
uint_fast16_t
. uint64_t
may be useful, too, for making an array of values aligned at 8-byte boundaries. This is unlikely to give you much benefits, though, because it comes at the price of wasting 75% of memory allocated for the array, along with the associated loss in cache performance.
Note: you may end up using the same type as uint64_t
if your library maps uint_fast16_t
to uint64_t
.