I am been trying some configurations to create bitboards for a large board of 90 cells (Xiangqi). The purpose is to compare them for pros-cons as well as speeds.
The first try is to use an array of 3 integer 32 bit. Everything is fine, the bitboard size (use sizeof) is exactly 12 byes (96 bit).
Now, I am trying to create other bitboard with one 64-bit integer and one 32-bit integer. (it is actually a Bob's suggestion long time ago).
phhnguyen wrote:I am been trying some configurations to create bitboards for a large board of 90 cells (Xiangqi). The purpose is to compare them for pros-cons as well as speeds.
The first try is to use an array of 3 integer 32 bit. Everything is fine, the bitboard size (use sizeof) is exactly 12 byes (96 bit).
Now, I am trying to create other bitboard with one 64-bit integer and one 32-bit integer. (it is actually a Bob's suggestion long time ago).
However the first problem here is the size of the bitboard now is not 12 bytes / 96 bits but 16 bytes / 128 bits - a redundancy of 4 bytes.
I have some understandings the way computer allocs memory but still curious: if there is anyway to make that class to be exactly 12 bytes?
Of course the compiler has to pad the structure, so each element of an array of structures has proper alignment; which is actually necessary on some platforms.
You can try to use #pragma pack(n), in your case 4, but I'd discourage you to do so; on x86/x64 it will work.
So I would happily use 2x uint64_t (128 bits) instead (or live with the fact the struct is 4-byte padded)
You can make a struct with three 32-bit integers and then it will only take 12 bytes. Since you have a 64-bit integer in there, the compiler makes the size of the struct a multiple of 8 bytes so the 64-bit integers are always aligned.
You could also just use a 128-bit integer type, which in gcc is `unsigned __int128'.