Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Boolean 4 bytes...?

Boolean 4 bytes...?

Scheduled Pinned Locked Moved The Lounge
question
25 Posts 11 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    alex barylski
    wrote on last edited by
    #1

    Why is it boolean is 4 bytes in most languages...? This makes no sense, theres 31 bits going to waste...??? Is this so you can perform some fancy bit shifting, ANDing, ORing and store 32 on/off's in one bool...? Just curious! "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr

    T T H B 4 Replies Last reply
    0
    • A alex barylski

      Why is it boolean is 4 bytes in most languages...? This makes no sense, theres 31 bits going to waste...??? Is this so you can perform some fancy bit shifting, ANDing, ORing and store 32 on/off's in one bool...? Just curious! "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr

      T Offline
      T Offline
      Tim Smith
      wrote on last edited by
      #2

      For most systems these days, 4 bytes are the fastest value to fetch from memory. Tim Smith Descartes Systems Sciences, Inc.

      S A 2 Replies Last reply
      0
      • T Tim Smith

        For most systems these days, 4 bytes are the fastest value to fetch from memory. Tim Smith Descartes Systems Sciences, Inc.

        S Offline
        S Offline
        SimonS
        wrote on last edited by
        #3

        Tim Smith wrote: 4 bytes are the fastest value to fetch from memory I know about 32bit/64bit systems, but I don't really understand why it would be faster. Please explain (I haven't quite finished my 8th Phd ). Cheers, Simon X-5 452 rules.

        T A 2 Replies Last reply
        0
        • A alex barylski

          Why is it boolean is 4 bytes in most languages...? This makes no sense, theres 31 bits going to waste...??? Is this so you can perform some fancy bit shifting, ANDing, ORing and store 32 on/off's in one bool...? Just curious! "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr

          T Offline
          T Offline
          Todd C Wilson
          wrote on last edited by
          #4

          Eh, this depends on the compiler vendor and the platform. With Microsoft, you can twiddle the #pragma pack statement to change this. Or use the unsigned int xyz:1 statement. Or better yet, post in the right forum. In any case, the alignment of 32 bits (64 on some, 16 on others) is designed to keep the data cache aligned up nicely.


          Visual Studio Favorites - www.nopcode.com/visualfav

          A 1 Reply Last reply
          0
          • S SimonS

            Tim Smith wrote: 4 bytes are the fastest value to fetch from memory I know about 32bit/64bit systems, but I don't really understand why it would be faster. Please explain (I haven't quite finished my 8th Phd ). Cheers, Simon X-5 452 rules.

            T Offline
            T Offline
            Todd C Wilson
            wrote on last edited by
            #5

            You can get all the dirty details at intel.com in their processor whitesheets, but basically, it has to do with the alignement of the data for the cache. The cache is optimized for 32-bit words for x86 processors.


            Visual Studio Favorites - www.nopcode.com/visualfav

            1 Reply Last reply
            0
            • A alex barylski

              Why is it boolean is 4 bytes in most languages...? This makes no sense, theres 31 bits going to waste...??? Is this so you can perform some fancy bit shifting, ANDing, ORing and store 32 on/off's in one bool...? Just curious! "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr

              H Offline
              H Offline
              Henry Jacobs
              wrote on last edited by
              #6

              DWORD alignment

              N 1 Reply Last reply
              0
              • H Henry Jacobs

                DWORD alignment

                N Offline
                N Offline
                NormDroid
                wrote on last edited by
                #7

                32bits! Normski. - Professional Windows Programmer

                M 1 Reply Last reply
                0
                • T Tim Smith

                  For most systems these days, 4 bytes are the fastest value to fetch from memory. Tim Smith Descartes Systems Sciences, Inc.

                  A Offline
                  A Offline
                  alex barylski
                  wrote on last edited by
                  #8

                  True, but the compiler could pack 4 - 1 byte booleans into 4 byte variable. I've thought of the DWORD alignment for avoiding...whats the word i'm looking for..??? memory stalls...wasted clocks, but still seems like an aweful waste of space.. Well actually....@^$&^$%$%&*@$%$%@^*)^@$&*@$%%$(* fast forward duh...I guess 31 bits here and there isn't huge, but it does kinda not make sense. My best impression of funny noises a CD player makes when forwarding/rewinding kinda loks like a regex huh...? ;P "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr

                  K 1 Reply Last reply
                  0
                  • S SimonS

                    Tim Smith wrote: 4 bytes are the fastest value to fetch from memory I know about 32bit/64bit systems, but I don't really understand why it would be faster. Please explain (I haven't quite finished my 8th Phd ). Cheers, Simon X-5 452 rules.

                    A Offline
                    A Offline
                    alex barylski
                    wrote on last edited by
                    #9

                    simons wrote: I haven't quite finished my 8th Phd ). Are you serious...? I haven't quite finished highschool... ;P So whats a guy with 8 phd's called...Doctor's doctor...? "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr

                    S R 2 Replies Last reply
                    0
                    • T Todd C Wilson

                      Eh, this depends on the compiler vendor and the platform. With Microsoft, you can twiddle the #pragma pack statement to change this. Or use the unsigned int xyz:1 statement. Or better yet, post in the right forum. In any case, the alignment of 32 bits (64 on some, 16 on others) is designed to keep the data cache aligned up nicely.


                      Visual Studio Favorites - www.nopcode.com/visualfav

                      A Offline
                      A Offline
                      alex barylski
                      wrote on last edited by
                      #10

                      Right forum...? This is a conceptual kinda sorta question...I wasn't asking WHY in Visual C++ it's like this...I know why...32 bit processor is why...DWORD alignment is why...i wanted to why...why...get others opinions why... I'm NOT baffled just curious why the compiler doesn't keep a count of bools and perfom the funny bit shifting ANDing ORing on the 32 bits instead of using mov to push and pull DWORDS around with only one active bit. It's not a waste of time, but rather of space. "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr

                      T 1 Reply Last reply
                      0
                      • A alex barylski

                        Right forum...? This is a conceptual kinda sorta question...I wasn't asking WHY in Visual C++ it's like this...I know why...32 bit processor is why...DWORD alignment is why...i wanted to why...why...get others opinions why... I'm NOT baffled just curious why the compiler doesn't keep a count of bools and perfom the funny bit shifting ANDing ORing on the 32 bits instead of using mov to push and pull DWORDS around with only one active bit. It's not a waste of time, but rather of space. "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr

                        T Offline
                        T Offline
                        Todd C Wilson
                        wrote on last edited by
                        #11

                        No, it would be a waste of both time and space, because the processor will not be able to do something like (pseudo-code): loadregister address but will need to do: loadregister #0x01 barrelshift left bitposition andmask address barrelshift right bitposition You're trading off 3 extra bytes of data memory (which is 1 time in memory) for a minimum 4x increase of code for each access of that bit. Now, if your overriding concern is memory storage (such as a huge table of bit data), then it is your job, as the developer, to inform the compiler to pack them tigher, probably by using the afor-mentioned unsigned int xyz:1 statement. But you're trading off speed & code size to reduce data memory consumption.


                        Visual Studio Favorites - www.nopcode.com/visualfav

                        A 2 Replies Last reply
                        0
                        • N NormDroid

                          32bits! Normski. - Professional Windows Programmer

                          M Offline
                          M Offline
                          MarkyMark
                          wrote on last edited by
                          #12

                          This is a C++ BOOL you're talking about is it? a BOOL (int) is 4 bytes but a bool is only one.

                          A 1 Reply Last reply
                          0
                          • A alex barylski

                            simons wrote: I haven't quite finished my 8th Phd ). Are you serious...? I haven't quite finished highschool... ;P So whats a guy with 8 phd's called...Doctor's doctor...? "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr

                            S Offline
                            S Offline
                            SimonS
                            wrote on last edited by
                            #13

                            HockeyDude wrote: Are you serious...? er... no. :-O :-O Cheers, Simon X-5 452 rules.

                            D A 2 Replies Last reply
                            0
                            • A alex barylski

                              Why is it boolean is 4 bytes in most languages...? This makes no sense, theres 31 bits going to waste...??? Is this so you can perform some fancy bit shifting, ANDing, ORing and store 32 on/off's in one bool...? Just curious! "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr

                              B Offline
                              B Offline
                              Brigg Thorp
                              wrote on last edited by
                              #14

                              This is the kind of crap that make applications enormous. How many values could have been fit into a single boolean bit value, only to take up 32 bits instead. Imagine if I had a bit array, with 100 booleans. That is 3100 bytes (3.1Kb) of wasted space. This also happens with hard drive cluster size as well. Whose stupid idea was this anyway? No wonder all new computers are coming with 100+ Gb drives. Jeesh End of rant... Brigg Thorp Software Engineer Timex Corporation

                              D 1 Reply Last reply
                              0
                              • A alex barylski

                                simons wrote: I haven't quite finished my 8th Phd ). Are you serious...? I haven't quite finished highschool... ;P So whats a guy with 8 phd's called...Doctor's doctor...? "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr

                                R Offline
                                R Offline
                                Ray Hayes
                                wrote on last edited by
                                #15

                                HockeyDude wrote: So whats a guy with 8 phd's called...Doctor's doctor...? Maybe! When I lived in Germany, I rented a flat from a local Uni Professor, his contact name/address started Herrn Professor Doktor Doktor Stroubler (maybe a couple of spelling mistakes there though, it is FRIDAY afternoon and I went to the pub at lunch :) !) Regards, Ray

                                A 1 Reply Last reply
                                0
                                • S SimonS

                                  HockeyDude wrote: Are you serious...? er... no. :-O :-O Cheers, Simon X-5 452 rules.

                                  D Offline
                                  D Offline
                                  dandy72
                                  wrote on last edited by
                                  #16

                                  A distant relative of mine had at least 6 a few years ago. He had a few more going simultaneously, so he's probably over 8 by now. Mind you, he was the prime example of "a genius is someone who can do anything except earn a living".

                                  1 Reply Last reply
                                  0
                                  • B Brigg Thorp

                                    This is the kind of crap that make applications enormous. How many values could have been fit into a single boolean bit value, only to take up 32 bits instead. Imagine if I had a bit array, with 100 booleans. That is 3100 bytes (3.1Kb) of wasted space. This also happens with hard drive cluster size as well. Whose stupid idea was this anyway? No wonder all new computers are coming with 100+ Gb drives. Jeesh End of rant... Brigg Thorp Software Engineer Timex Corporation

                                    D Offline
                                    D Offline
                                    dandy72
                                    wrote on last edited by
                                    #17

                                    Imagine how quickly your hard drive would fragment if each file was allocated space on a per-byte basis...

                                    1 Reply Last reply
                                    0
                                    • S SimonS

                                      HockeyDude wrote: Are you serious...? er... no. :-O :-O Cheers, Simon X-5 452 rules.

                                      A Offline
                                      A Offline
                                      alex barylski
                                      wrote on last edited by
                                      #18

                                      :-D "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr

                                      1 Reply Last reply
                                      0
                                      • R Ray Hayes

                                        HockeyDude wrote: So whats a guy with 8 phd's called...Doctor's doctor...? Maybe! When I lived in Germany, I rented a flat from a local Uni Professor, his contact name/address started Herrn Professor Doktor Doktor Stroubler (maybe a couple of spelling mistakes there though, it is FRIDAY afternoon and I went to the pub at lunch :) !) Regards, Ray

                                        A Offline
                                        A Offline
                                        alex barylski
                                        wrote on last edited by
                                        #19

                                        Whatever the case...someone with 8 phd's would be something other than human. Cheers "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr

                                        1 Reply Last reply
                                        0
                                        • A alex barylski

                                          True, but the compiler could pack 4 - 1 byte booleans into 4 byte variable. I've thought of the DWORD alignment for avoiding...whats the word i'm looking for..??? memory stalls...wasted clocks, but still seems like an aweful waste of space.. Well actually....@^$&^$%$%&*@$%$%@^*)^@$&*@$%%$(* fast forward duh...I guess 31 bits here and there isn't huge, but it does kinda not make sense. My best impression of funny noises a CD player makes when forwarding/rewinding kinda loks like a regex huh...? ;P "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr

                                          K Offline
                                          K Offline
                                          Kastellanos Nikos
                                          wrote on last edited by
                                          #20

                                          I can send you an old 64MB SIMM for free. That's 16.777.216 booleans. ;P - - - - - - - - - - - - - - - - - - Memory leaks is the price we pay \0 01234567890123456789012345678901234

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups