Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
BOOL Datatype
Message
From
10/04/2000 14:44:56
 
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Title:
Miscellaneous
Thread ID:
00357504
Message ID:
00357628
Views:
12
>This is really more about VC++ than VFP, but it's something that I've wondered about for a long period of time, and I'm hoping that someone out there might know the answer. First, a bit of background.
>
>Back when I was working in QuickBASIC, it was not uncommon to see something like this:
>CONST FALSE% = 0
>CONST TRUE% = NOT FALSE
Note that this code pre-dates the boolean data types of False and True currently available in VB. What the code above does in the first line is assign the value of 0 to the constant. The second line performs a bitwise NOT on the assigned constant and assigns the result to another constant. As a result of the above the TRUE constant had a value of -1. In fact, these same values correspond to the ones used by VB for its Booleans today.
>
>Now in regards to C++ and specifically the API, there are a number of functions that return a BOOL (Boolean) data type. Like VB, logical false will be equal to zero. Unlike, VB (and the result of performing a bitwise NOT on 0), these functions return 1 rather than -1. I'm just wondering if anyone knows why.
>
>My curiousity got piqued when I recently upsized a table to SQL server. In that environment, Boolean fields are stored as a bit. Naturally, -1 isn't really possible there, since you'd need at least a second bit to determine the sign. However, I sincerely doubt that C++ would do something similar since the smallest portion of addressable memory is a byte, and breaking a byte down into 8 individual BOOLs seems rather silly, not to mention the overhead difficulties that would be created.
>
>Any comments would be appreciated.

I was going to argue that C, as a precursor of C++, predates BASIC, but it does not - apparently BASIC was invented in 1964. However, C does predate QuickBASIC. (I wonder, if the old big-iron BASIC treated TRUE and FALSE the same way as QB?)

Since I can't argue that C predates BASIC and therefore BASIC should conform to C and not the other way around, I'd have to argue space efficiency. As you pointed out, using 0 and 1 lets you store a boolean in a single bit. In these days of HD prices dropping to the $1/GB level, we forget how expensive storage used to be.

Now you might wonder, if HD prices are so low, why does SQL Server still store booleans as bits? If earlier versions did the same thing, backwards compatibility would be a compelling reason. However, you might also be able to argue that efficiency is important as well.

Modern DBMSs will achieve peak performance only with data held in RAM cache. If these servers are disk-bound then they have CPU cycles to burn, and overhead in converting 1 byte to 8 bits may be of little consequence, compared to paging out to disk. So, to get the most mileage out of the usually limited and precious RAM, using 1 bit instead of a whole byte may actually improve overall performance.

So, I guess efficiency will never truly go out of style :-)
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform