I am writing a piece of code designed to do some data compression on CLSID structures. I\'m storing them as a compressed stream of 128 bit integers. However, the code in questio
You should measure rather than guess at any potential improvement but my first thought is that it may be faster to do a union as follows:
typedef union {
DWORD d;
struct {
BYTE b0;
BYTE b1;
BYTE b2;
BYTE b3;
} b;
} DWB;
std::vector compBytes;
DWB invLen;
invLen.d = (DWORD) invalidClsids.length();
compBytes.push_back(invalidLength.b.b3);
compBytes.push_back(invalidLength.b.b2);
compBytes.push_back(invalidLength.b.b1);
compBytes.push_back(invalidLength.b.b0);
That may be the right order for the pushbacks but check just in case - it depends on the endian-ness of the CPU.