If you're using C++ and are willing to use gcc (and clang) extensions,
you can do a bit better, e.g.:
class __attribute__((packed)) int24_t
{
public:
operator int () const { return b; }
int24_t (int v) : b (v) {}
int24_t () {}
private:
int b : 24;
};
Then an array like "int24_t a[1000]" will only take 3000 bytes, and
you can kinda/sorta mix int24_t types with integers...
Of course the generated code is not so efficient, so don't use such
types in inner loops if you can help it!
[Dunno if C++11 has any more portable replacement for the
__attribute__((packed))...]
-miles
--
雨上がり に歩いて、風 柔らかい