[Pyrex] array.array vs long ints for bit vectors

Nitin Madnani nmadnani at wam.umd.edu
Sun Oct 30 07:11:45 CET 2005


Hi Guys

I am planning to use a bit vector as a member of an extension type. I  
first thought that I can easily do this by just using a long int for  
the vector but then I realized that I would like the bit vector to  
grow only to the size needed (which would be defined by an argument  
to the __init__ method of the type. So, then I remembered the 'array'  
module but then this would also store each bit as a byte (according  
to the python documentation). So, if I had a 20-bit map, 'array'  
would take >20 bytes to store this bitmap (only the buffer would be  
20 bytes) ? I have also read that a long int also comes with a bit of  
baggage.

So, is there no other memory-efficient option other than to write an  
extension myself? However, I am guessing whatever I come up with  
would be slower compared to the both long ints and arrays. So, should  
I just bite the bullet and live with the wasted memory ?


Thanks !
Nitin

PS: I know this question is sort of out of place here but since I am  
planning to use it in Pyrex, I wanted to ask it here. I also know  
little about either long ints or the 'array' module, so please  
correct me if I am being completely naive.




More information about the Pyrex mailing list