
Dave Harris wrote:
Specifically, I'd use a byte oriented scheme where the low 7 bits of each byte contribute to the current number, and the high bit says whether there are more bytes to come.
...
Thus integers less than 128 take 1 byte, less than 16,000 take 2 bytes etc. This gives a compact representation while still supporting 64-bit ints and beyond. You can use boost::numeric_cast<> or similar to bring the uintmax_t down to a smaller size.
I would use something similar, but I would store all integers as 2s-complement signed values. An unsigned value with 'n' significant bits would be stored as a signed value of no less than 'n + 1' bits. This means that if the type of a variable is changed from a signed type to an unsigned type or vice versa, the program can still read all old archives so long as all of the values in the old archives fit into the new variables. -- Rainer Deyke - rainerd@eldwood.com - http://eldwood.com