Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Two values in one variable

Name: Anonymous 2010-01-16 18:52

Let's say you have two small values that will never get past 10, and you use the first four bits of a char for the first var and the last bits for the second var. Do people do that?

Name: Anonymous 2010-01-16 19:13

>>4
That's not optimizing for memory use. It's optimizing for stupidity, unless you're going to have a lot of these variables around (as in a huge array and/or dynamically allocated), as the code to access them this way will easily outweigh the space savings. (hint: a shift+mask will cost you at least 4, maybe 8 bytes on code size; also reducing an int to byte may very well be useless depending on alignment/padding constraints, so you have to know what layout stuff will actually have in memory)

tl;dr: it you have to ask, it's a bad idea for you to do it

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List