Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Performance benefit when using uint_fast8_t?

So after researching engines a lot I've been building a 2d framework for the iphone. As you know the world of engine architecture is vast so I've been trying to apply best practices as much as possible.

I've been using:

uint_fast8_t mId;

If I look up the definition of uint_fast8_t I find:

/* 7.18.1.3 Fastest-width integer types */
...
typedef uint8_t          uint_fast8_t;

And I've been using these types throughout my code - My question is, is there a performance benefit to using these types? And what exactly is going on behind the scenes? Besides the obvious fact that this is correct data type (unsigned 8 bit integer) for the data, is it worthwhile to have this peppered throughout my code?

Is this a needless optimization that the compiler would probably take care of anyways?

Thanks.

Edit: No responses/answers, so I'm putting a bounty on this!

like image 656
mr-sk Avatar asked Dec 23 '09 16:12

mr-sk


2 Answers

the "fast" integer types are defined to be the fastest integer type available with at least the amount of bits required (in this case 8).

If your platform defines uint_fast8_t as uint8_t then there will be absolutely no difference in speed.

The reason is that there may be architectures that are slower when not using their native word length. E.g. I could find one reference where for Alpha processors uint_fast_8_t was defined to be "unsigned int".

like image 125
Axel Gneiting Avatar answered Oct 18 '22 23:10

Axel Gneiting


An uint_fast8_t is the fastest integer guaranteed to be at least 8 bits wide. Depending on your platform it could be 8 or 16 or 32 bits wide.

It isnt taken care of by the compiler itself, it does indeed make your program execute faster

Here are some resource I found, You might already have seen them http://embeddedgurus.com/stack-overflow/2008/06/efficient-c-tips-1-choosing-the-correct-integer-size/

http://www.mail-archive.com/[email protected]/msg03149.html

like image 34
anijhaw Avatar answered Oct 19 '22 00:10

anijhaw