was wondering if you could comment on the following.
One can code these and respective routines (set/reset and test) in a
number of ways. A good overview is here: http://en.wikipedia.org/wiki/Bit_field
Has anyone done any performance test on amd64 type system with a
recent enough of a gcc compiler to compare the boolean bit magic vs
bit fields in terms of performance and memory efficiency ?
Say one has a need for 32 flags. These can be packed in a single
unsigned int through traditional boolean logic. What if one defines
them as 32 bit fields - would they still occupy same 4 bytes and will
access to the bit fields be as efficient ?
--
comp.lang.c.moderated - moderation address: cl...@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
> One can code these and respective routines (set/reset and test) in a
> number of ways. A good overview is here:
> http://en.wikipedia.org/wiki/Bit_field
>
> Has anyone done any performance test on amd64 type system with a
> recent enough of a gcc compiler to compare the boolean bit magic vs
> bit fields in terms of performance and memory efficiency ?
I believe there would be no performance difference when the
compiler makes use of hardware based routines. That aside, if
you are looking for the answer for an academic purpose I can
understand but I would not bother for performance issues between
these two if the concern is my application code. I do not think
they would bottleneck performance in general.
> Say one has a need for 32 flags. These can be packed in a single
> unsigned int through traditional boolean logic. What if one defines
> them as 32 bit fields - would they still occupy same 4 bytes and will
> access to the bit fields be as efficient ?
Yes, if unsigned int is 32 bits it will still take 32 bits only. Personally
I would not try to think about the efficiency here in my code, I would use
that
which is easier to read and maintain.
Regards,
Jyoti