Reputation: 25862
Let's say I were to design a low level language, just for example. What is the actual smallest datatype for a variable I can have? Let's say for example the primitive boolean in java only needs 1 bit, what is the actual memory footprint (memory size) that it uses?
Upvotes: 0
Views: 759
Reputation: 535
Not all 32 bit processor architectures were created equal, and not all implementations of a given architecture have the same word size. It ultimately depends on the processor itself. 8, 16, and 32 bit word sizes are all common on 32 bit systems. Memory addresses are (usually--as Paul R pointed out below, systems exist where the smallest address is a word size) assigned every byte, which is usually 8 bits (though it doesn't have to be--I'm not aware of a non-theoretical architecture where it isn't, but I'm sure one exists). So the smallest amount of memory you can meaningfully allocate is 1 byte.
Upvotes: 0
Reputation: 8150
It depends on your target platform. The smallest addressable memory unit is 1 byte (8-bits) on x86. That being said, you can design your language to manipulate individual bits of a byte much like C and C++ bit fields do. However, under the hood the compiler needs to generate some fancy bit operations at the byte level to twiddle those bits.
Upvotes: 0
Reputation: 96258
Theoretically you could have a variable that only occupies 1 bit. The compiler would then generate a code that gets one byte and gets the information out of it with bit manipulating (&, shift).
If you use some kind of compression to store the data and retrieve the data associated with that variable it could be even less than a bit...
Upvotes: 0
Reputation: 84159
The smallest directly addressable entity is the byte, which is normally eight bits nowdays. Then nothing prevents you from packing multiple high-level-language booleans in there, but that would involve runtime overhead of shifting and masking, so it's a trade-off.
Upvotes: 5