Friday, May 21, 2010

Is there a reason that Visual Basic (and variants) boolean data type is 16bit and not a single bit?

Most of the languages I've worked with use a single bit for the boolean data type, it's either set (1) for true or isn't (0) for false. At least that's my understanding of it.





But VB and it's variations use a signed 16 bit integer for a boolean data type, setting it as 0x0000 (0) for false and 0xFFFF (1) for true.





Why does VB use those extra 15 bits? Would it not be somewhat easier and space saving to use single bit booleans?





Sorry if I seem dense.

Is there a reason that Visual Basic (and variants) boolean data type is 16bit and not a single bit?
True it would save space but then you're limited. In fact too limited for a GUI type interface (in the minds of MS).





Microsoft has always been in the graphical user interface arena a space hog. Their OS uses too much memory and now you know why. Other GUI utilize a lot less RAM to do the same thing but for whatever reason they have decided on this enormous amount of programing to get things done.
Reply:You're not dense: that doesn't make a lot of sense. On 32 bit machines, using 32 bit variables usually speeds up execution, even if you only intend to use 1 bit. In that case, it would make sense if bool were 32 bit. Maybe it is 16 because it harkens back to 16 bit computing days... Using 1 bit would be the more memory saving option, it's the minimum amount we can use, at the expense of extra instruction cycles.
Reply:I hope that You know that any variables used in a program are name for memory locations. i.e. all variables are stored in memory. In Memory architecture, you may have heard that, memory is either byte addressed or word addressed. Generally, memory is word addressable, i.e, the smallest unit of storage that can be accessed as a unit is a word . A word of memory is generally 16-bit in older computer to 64-bit in modern computer. So, boolean variable in older architecture (operating system) takes 16 bit.


No comments:

Post a Comment