Author: Dann Corbit
Date: 18:55:29 12/05/03
Go up one level in this thread
On December 05, 2003 at 21:24:19, Robert Hyatt wrote:
>I have a structure that looks like this:
>
>struct BOOK_POSITION {
> long long signature;
> unsigned int status;
> float learn;
> int CAP;
>}
>
>sizeof(above) gives 20 on my dual xeon, 24 on the
>opteron. I'd like to make it 20 so that my binary book
>can be shared between the opteron and the rest of the
>intel world.
>
>Is there a reasonably portable way to fix this???
>
>(note the long long becomes a long on the opteron, the rest
>are not changed.)
GCC has a packing pragma.
Warning: Bad packing will slow things down a lot.
Un-warning: For an opening book, it does not matter. But for some structure in
a deeply nested loop, prying out a character aligned on a fault boundary will be
wicked slow.
In other words, pragma pack all you want around something that does not need
lightning speed.
Another solution is to pad all your data objects to a forced biggest size that
you know of.
For instance:
typedef union tag_kludge {
unsigned int uiVal;
char[8] caVal;
} kludge; // Kludge takes 8 bytes at max until a machine with 16 byte integer...
The problem with using a kludge is two-fold. First, it is awfully ugly.
Second, you have to change your notation from:
uiVal++;
to:
kludge_thingy.uiVal++;
Icky, icky, icky.
Also, the pragma has an Achilles' heel. Every compiler implements the pack
pragma different (if at all). So now you are only portable within a single
compiler (how's that for irony)?
Suggestion:
Keep the opening book in a database like FastDB or Sqlite. Since it is binary,
probably FastDB would be better.
Plus now you will be able to do much more sophisticated queries like:
SELECT ce, pm, bm, am, win_percentage FROM OpeningBook WHERE win_percentage >
0.5 AND played_elo > 2500 order by elo, win_percentage
or whatever. FastDB is all in-memory but also persistent on disk. It does not
use SQL directly like above, but the differences are minor enough to make it
obvious how to use it.
http://www.garret.ru/~knizhnik/fastdb/FastDB.htm
http://www.hwaci.com/sw/sqlite/
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.