Optimizing for binary storage/bit-fiddling

Thomas Weholt 2002 at weholt.org
Sat May 4 08:37:05 EDT 2002


I'm working on a very simple object storage system ( there are alot of
alternatives I know :-) ) where I got a "record" referencing to a pickled
object in a large file. This record is constructed using the struct-module.
The format consists of 4 integers, 1 float and at the point 4 boolean
values. Currently I'm using a struct-format like so 4If4F. But with
bit-fiddling I should get all the boolean values into one integers shouldn't
I? Of the 4 integers 2 of them will never exceed 256 so I should be able to
use something else than integers for this also ???

A simple search on Google gave me a few hits on the subject, but I read
Python wasn't optimized for bit-fiddling. Would it be much faster to just
ignore the space issue and use integers for boolean values? Any thoughts?

In conclusion: what is the most efficient way to store very large integers
( 0, -> ), very small numeric values ( 0-512 ) and boolean values in a
binary file? Is the bit-fiddling so slow I should avoid it in circumstances
like this?

PS! Any good references on very, very simple bit-fiddling ( tutorials etc. )
would also be highly appreciated.

Best regards,
Thomas Weholt,
a novice in this area :)





More information about the Python-list mailing list