boolean compression (c++)

Started by
10 comments, last by Yohomyth 20 years, 3 months ago
by doing this, you''re essentially trading speed for space... and well, unless you have ALOT of booleans, it''s not going to be worth it.

the reasons booleans are ''1 byte'' is because that''s the smallest amount of space you can address on your target platform.

btw, nearly everyone knows about this ''space optimization'', and have implemented it much less naively (no offense).

a common idiom of this ''optimization'' in C++ is simply ..
char const FLAG_1 = 0x01;char const FLAG_2 = 0x02;char const FLAG_3 = 0x04;char flags = 0;flags |= FLAG_3;  //set flag_3.flags |= FLAG_1;  //set flag_1if(flags & FLAG_3)  do_something();  //if flag_3 is set 




Advertisement
This really doesn''t cost very much at all; it''s just a few bitwise operations, so it''s really fast (if done w/o function calls, etc). It''s usually not really necessary, but it really doesn''t hurt much.

There ARE some places where it actually makesd a lot of sense: Large voxel datasets representing solid objects, for example.

This trick will also make copying a given set of data 8x faster.

This topic is closed to new replies.

Advertisement