r/ProgrammerHumor • • Oct 07 '26

Meme wasteOfPreciousSpace

Post image
7.3k Upvotes

244 comments sorted by

View all comments

170

u/Spinnenente Oct 07 '26

nobody is stopping you from storing all your bools in a single long

welcome to optimization only neccessary before you were born.

56

u/AOAqua Oct 07 '26

Hey, it's still used sometimes. I've used it in high speed drivers, where every single extra byte decreases latency of the overall reaction. And bools for registers are stored like that as well because a single 4 byte variable literally manipulates a physical memory block

9

u/MattieShoes Oct 07 '26 edited Oct 09 '26

Bitboards in stuff like chess engines (64 bits, 64 squares, wow!)

I've screwed around with it for things like sieve method for finding primes. Also tried storing only multiples of 6 +/-1 for 1/3 of a bit per number, so a few gig of memory can hold like 100 billion numbers.

17

u/kinokomushroom Oct 08 '26

I use it in game development where you deal with 2D/3D grids of bitflags. Every bit counts.

10

u/BringBackManaPots Oct 08 '26

This sounds genuinely fun to program. Programming with tight constraints is the best

5

u/kinokomushroom Oct 08 '26

Graphics programming is basically wizardry.

2

u/BringBackManaPots Oct 08 '26

Hah it really will be if we assume relinquish all the doing to AI

1

u/DrMobius0 Oct 08 '26

Yeah, bit flags are nice. I've had more than a few cases where functions just kept accumulating boolean parameters, and at a certain point, you just realize that a bitflag makes the whole thing easier to deal with.

5

u/terjeboe Oct 08 '26

I was taught to always make a table in the docs explaining what each bit in flags did.  Makes it a little cumbersome to read. 

IF (BTEST(FLAGS,0)) THEN 

3

u/TabletopParlourPalm Oct 08 '26

I worked as a firmware engineer and we still do that now.

2

u/Fluffybear987 Oct 10 '26

Yup, same here!

2

u/rsqit Oct 08 '26

Someone’s never had to deal with fitting things into cache lines.

1

u/SanktusAngus Oct 09 '26

Bit flags. Yeay!