for a transpose table (usually a hash table) of Connect Four games, I would like to use memory efficiently (to save as many elements as possible). One element of the table should store the following information:
- lock: unsigned 64 bit
- move: [0..6] → unsigned 3 bits
- rating: [-2000..2000] → 12 bit signed
- flag: VALID, UBOUND, LBOUND: → unsigned 2 bit
- height: [-1..42]: → signed 7 bits
First, I tried the following data structure, which needs 24 bytes:
struct TableEntry1
{
unsigned __int64 lock;
unsigned char move;
short score;
enum { VALID, UBOUND, LBOUND } flag;
char height;
};
After rearranging the elements, 16 bytes are required (I found the answer for this behavior):
struct TableEntry2
{
unsigned __int64 lock;
enum { VALID, UBOUND, LBOUND } flag;
short score;
char height;
unsigned char move;
};
My last attempt:
struct TableEntry3
{
unsigned __int64 lock;
unsigned int move:3;
int score:12;
enum { VALID, UBOUND, LBOUND } flag:2;
int height:7;
};
16 . ,
12 ( 32- )? 12 ?
!
lock - -.