Assume that this is for a 32-bit application. I have two ID values which together uniquely identify a particular object. Each ID is a plain 32-bit int, so in order to identify any particular object I need to keep both ID values together.
The first solution that comes to mind is to store them is as two separate values, and pass them around in a struct:
struct {
int id1;
int id2;
};
However, it would be nice if I could pass them around as a single value rather than a struct pair, as I did back when there was only a single 32-bit ID value.
So, another idea is to store them as the upper and lower halves of a uint64_t.
My question is, is there any real difference between the two methods? Either way, the same number of bytes are being passed around, but I don’t know if there is any special overhead for int64, since the CPU isn’t natively handling 64-bit values.
If you can’t make up your mind, use a union.
Microsoft for example defines a
LARGE_INTEGERunion.