for the transposition table (generally a hash table) of a Connect Four game, I would like to use the memory efficiently (to store the most possible number of elements). One table element has to store following information:
- lock: unsigned 64 bit
- move: [0..6] --> unsigned 3 bit
- score: [-2000..2000] --> signed 12 bit
- flag: VALID, UBOUND, LBOUND: --> unsigned 2 bit
- height: [-1..42]: --> signed 7 bit
First I tried 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 it needs 16 Bytes (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 try was:
struct TableEntry3
{
unsigned __int64 lock;
unsigned int move:3;
int score:12;
enum { VALID, UBOUND, LBOUND } flag:2;
int height:7;
};
Which also needs 16 Bytes. Is it possible to change the structure so that it only uses 12 Bytes (on a 32 bit-architecture)? Why the compiler doesn't make my last try 12 bytes long?
Thanks!
Edit The property lock
is a unique element id to detect hash collisions.