views:

172

answers:

2

Hello,

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!

+3  A: 

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".

Axel Gneiting
Excellent answer.
Stephen Canon
If your platform defines uint_fast8_t as uint8_t then there will be absolutely no difference in speed.- Ah, so why do they even bother?
Mr-sk
@Mr-sk: Because you want your code to run on more than one platform. Say your algorithm requires at least 8 bits for the type, but does not require that it be *exactly* 8 bits. You would prefer to use a larger type on platforms where `uint8_t` will be a performance hazard. Solution? use `uint_fast8_t`.
Stephen Canon
Ah, ok makes sense to me. Thanks for the answer.
Mr-sk
A: 

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://www.embeddedgurus.net/stack-overflow/2008/06/efficient-c-tips-1-choosing-correct.html

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

anijhaw