Search code examples
iphonetypesgame-engine

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!


Solution

  • 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_fast8_t was defined to be unsigned int.