Original Post
Why the booleen ( in VC++) are very slow.
( a test in it do approximately 400% more time than an integer !)
!o)
typedef int BOOL
quote:
Original post by billybob
quite a few bools are part of structs of classes i would think.
edit: OR classes, not of
[edited by - billybob on July 21, 2003 8:42:13 PM]
quote:
Original post by RamboBonesquote:
Original post by billybob
quite a few bools are part of structs of classes i would think.
edit: OR classes, not of
[edited by - billybob on July 21, 2003 8:42:13 PM]
Yes they are but that has no meaning because we''re talking about using the value itself, it could be contained in my arse and it still wouldn''t make a difference, although that could be kind of hard.
Acessing ANY value in a class or struct automatically may bring overhead, so we can ignore that.
quote:
Original post by RamboBones
hehe, okay you want the explanation. Note: As stated in my post this explanation is ONLY about how doing ''if'' statements on bools brings very little slow down even when compared to 32 bits.
Okay, the reason is quite simple. When doing an ''if'' statement the binary code goes something like this, note my binary is scratchy so don''t expect anything big
move value(s) to some register, unless it''s already there
perform a cmp statement on the two values
to a conditional jump statement
Moving an 8bit value into a register is of course no problem, since some of the register''s are 8bits. Since, in this example, or your testing for is true or false you can compare the two 8bit values togehther, you don''t need to compare 8bit with 32bit and therefore waste alot of time (see below for reason).
Incase anybody''s wondering performing math operations on 8bit values can be slow because generally you have to move the 8bit value into a 32bit register/memory address, unless maybe your doing a math operation on two 8bit values. I say this because I believe you can''t do a math operation with one value being 8bit and one value being 32bit or 16bit etc. The slowness comes in when moving the 8bit to a different sized memory address becuase you have to padd with zeros, I''d presume that you''d clear the 32bit area to zero first then move the 8bit value in to the lower part of the 32bit area but hehe like I said my assembler scratchy, but the point is you have to padd with zero''s.
Okay I typed that up pretty fast so it''s bound to be full of mistakes, or other problems.
If what I''ve said is total bullshit could someone please tell me. Although I know that the underlying principle behind what I''ve said should be pretty much okay.
unsigned long ul32 = 1234567;
unsigned char uc8 = 123;
uc8 = ul32+uc8;
// same as
asm
{
lb $1, 0(sp)
lw $2, 4(sp)
add $3, $2, $1
sb $3, 0(sp)
}
ul32= ul32+uc8;
// same as
asm
{
lb $1, 0(sp)
lw $2, 4(sp)
add $3, $2, $1
sw $3, 4(sp)
}
quote:
Original post by Mithrandir
you know, it''s not like you''re doing number-crunching on bools... the overhead is in almost all cases insignificant to nonexistent.
This topic has been locked by a moderator. New replies are not allowed.
With your permission, GameDev.net uses analytics cookies to understand how people use the platform. You can accept analytics or continue with necessary cookies only. Learn more