Boolean 4 bytes...?
-
For most systems these days, 4 bytes are the fastest value to fetch from memory. Tim Smith Descartes Systems Sciences, Inc.
-
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
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
-
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.
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
-
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
DWORD alignment
-
DWORD alignment
-
For most systems these days, 4 bytes are the fastest value to fetch from memory. Tim Smith Descartes Systems Sciences, Inc.
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
-
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.
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
-
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
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
-
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
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
-
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
-
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
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
-
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
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
-
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 "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
-
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
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
-
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
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
-
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
Thats the response I was looking for. See initially i wasn't even thinking about the the clock cycles expended for shl, shr never mind the size of instruction(s). All I was thinking was that 4 bytes on a 32 bit processor fits like hand in glove, but those poor 31 remaining bits must get some lonely. Yes after double checking with intel docs it occured to me...IT's a waste of space yup, but it'd be more with the added instructions shl, shr. Hell I almost went to lengths of exemplifying my own mistake...I was gonna find the difference in clocks and and code size and show you how right you were, but decided showing someone how right they were cuz how wrong I was, isn't acceptable. Congrats...I'm never wrong...not that i'm a genius, I just don't speak unless I know what i'm talking about or perhaps with as much authority. Not that i was trying to be authoritive, just didn't quite find yoer comment about asking in the right forum appropriate. I've asked numerous conceptual, theory questions there. Thats what i was looking for, not technical...i figure thats what books are for, but in this case it proved beneficial. Ah well tis what i get for speaking before thinking. Ummm...I'm super tired...damn computer keeps me awake for days...I slept yesterday though...poor excuse for bad judgement I agree, but it's an excuse. ;P
shl eax, 2
Is only 2 cycles and 3 bytes so i wasn't "that" wrong...but I was wrong... Cheers! "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
-
This is a C++ BOOL you're talking about is it? a BOOL (int) is 4 bytes but a bool is only one.
In Visual C++ 5.0 and later yup. Actually the question stemed from my old TurboPascal program, which uses 4 bytes for boolean also. "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr