B
bartc
jacob navia said:I am implementing the bitstring type in the container library, and
obviously I store the number of bits in a size_t...
Problem is, in 64 bit versions, size_t grows to 8 bytes, what
is an absolute overkill for a number that in most cases will
fit in 16 bits, or, at most 32.
Bitstrings are the ones most in need of a 64-bit count; if you have 4GB'
worth of bytes, that's 32G bits.
Otherwise your argument can be applied to any 64-bit C system and any
datatypes, that size_t is overkill for an array or string of 2 or 3 bytes.
If the implementation of bitstring is hidden, then it's already been
suggested that you could use a variable-length count, returning a size_t (of
whatever width) to a length request.
But, it sounds like you will already have to use a 64-bit pointer to the bit
data, and your minimum allocation for the bitstring is likely at least 16
bytes (128 bits), so 64-bits for a length won't make much difference.
(This is a general problem with 64-bits I think; everyone wants 64-bit data
and the ability to move stuff around 64-bits at a time, but fewer are
interested in addressing more than 4GB of data in each task. Being forced to
almost double the memory needs in some cases, will cancel much of the
advantage.)