performance - Pros/cons to using char for small integers in C -
Is there a disadvantage in using char
for the small integer? What is the benefit other than occupancy / memory benefit?
Specifically, the processor is likely to face with integer arithmetic on a char
, better than or worse (a long
/ < Code> short ) int
?
I know that this processor / system / compiler will be unique, but I am hoping to respond normally, or, at least, the normal case for 32-bit Windows and Solaris, I present I'm working on the system. I also agree that things like Overflow / Cover Problems have already been dealt with.
Update: In Visual Studio 6.0, exactly like As a side note, I have not spent a lot of time, but (via) C99 Added so called 'Fastest' minimum-width integer type to solve this problem For the category that interests you, type Keep in mind that there may be no performance gain (the increase in memory consumption may be slow); As always, the benchmark! stdint.h
Christopher has not suggested that one with windows on stacks (VS 6.0, debug build, 32-bit) Small benchmarking gives int
and long
to provide similar performance, which is almost twice as fast as four
. The same test on Linux is similar to int
and long
running with GCC, and both are faster than char, though the difference is less clear.
uint_fast8_t
defines unsigned char
Despite this, at least in my trials slow, thus the moral of the story, as Christopha correctly suggests: always the benchmark! int_fast8_t
and uint_fast8_t
, which can be found in stdint.h
.
Comments
Post a Comment