Pros and cons of ways of storing an unsigned int without an unsigned int data type
Posted
by fields
on Stack Overflow
See other posts from Stack Overflow
or by fields
Published on 2010-02-18T13:31:32Z
Indexed on
2010/03/18
5:51 UTC
Read the original article
Hit count: 339
I have values that are 64-bit unsigned ints, and I need to store them in mongodb, which has no unsigned int type. I see three main possibilities for storing them in other field types, and converting on going in and out:
Using a signed int is probably easiest and most space efficient, but has the disadvantage that they're not human readable and if someone forgets to do the conversion, some of them will work, which may obscure errors.
Raw binary is probably most difficult for inexperienced programmers to deal with, and also suffers from non-human-readability.
A string representation is the least space efficient (~40 bytes in unicode vs 8 bytes per field), but then at least all of the possible values will map properly, and for querying only a conversion to string is required instead of a more complicated conversion.
I need these values to be available from different platforms, so a single driver-specific solution isn't an option.
Any major pros and cons I've missed? Which one would you use?
© Stack Overflow or respective owner