Sign in to follow this  

New Questions - Uint8 & uint8_t & SDL?

This topic is 3464 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm looking at some code that use Uint8. I understand it only uses a byte, but why use it? I could just as easily use int. Is there a performance difference? or (as i'm thinking) a memory thing? [Edited by - frogtag on June 23, 2008 3:37:01 PM]

Share this post


Link to post
Share on other sites
Depends on the context. It could be used in an unpadded structure where it's important to know the exact size (in bytes) of the member variables because it might be read from disk.

So how about posting where you found this, then we can comment on its usefulness.

Share this post


Link to post
Share on other sites
It's from a skeletal animation tutorial on GPWiki. It the best example of skeletal animation i could find that actually explains and shows how to do it from scratch, and not using a 3D art pack.

Tutorial

Share this post


Link to post
Share on other sites
You're right, *usually*, the only reason to use smaller datatypes than int, is to conserve memory (or diskspace or network bandwidth or whatever)

There's generally no performance benefit from doing this, On the contrary, it may be slower than if you'd used an int.

Of course the exception is in cases where the smaller memory footprint can lead to improved performance (for example by letting your data fit in the CPU cache)

Share this post


Link to post
Share on other sites
Thank you for the explaination, it helped.

Also New questions

1) What about uint8_t is that the same thing?

2) Which include file are Uint8 (& uint8_t) defined in? I'm currently using an SDL header.

3) SDL. Is it any good? and what at?

Share this post


Link to post
Share on other sites
Quote:
Original post by frogtag
1) What about uint8_t is that the same thing?

Typically, yes. Unlike Uint8 though, uint8_t is an official C/C++ type.

Quote:
Original post by frogtag
2) Which include file are Uint8 (& uint8_t) defined in? I'm currently using an SDL header.

Uint8 probably comes from the SDL header, or something it includes. It's not a standard C type, and many libraries feel like defining these kind of types. uint8_t can be found in <stdint.h>

Quote:
Original post by frogtag
3) SDL. Is it any good? and what at?

[/quote]
Yes. At cross-platform 2D graphics, keyboard and mouse input, threading, timers and audio playback. 3D graphics is also supported through OpenGL, but I'm not sure how supported that is. There seem to be tutorials for it, so I guess it must work :)

Share this post


Link to post
Share on other sites
Quote:
Original post by Mike nl
Typically, yes. Unlike Uint8 though, uint8_t is an official C/C++ type.

uint8_t is a typedef that may be defined in C99 implementations if stdint.h is included. It's not an integral type in the same way that int or char are and it may not even be present if the platform doesn't support 8 bit integral types. In C++, uint8_t shows up nowhere in the standard.

Share this post


Link to post
Share on other sites

This topic is 3464 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this