Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

TheSimplerOne

Variable types

This topic is 5225 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

Well in my book it talks about int, double, char, etc. Well, it also mentions long and short and unsigned and signed. I think I understand most of this, but is it even neccessary? In school all they taught us was int, double, char, and apstrings. Is it neccessary to get used to float, long, unsigned, etc...if so in what specific cases? Computers are so fast nowadays and all that I just wanted to know if it was worth the trouble trying to save a few bytes.

Share this post


Link to post
Share on other sites
Advertisement
Its more for compatibility than for space. You''ll mostly be using ints and doubles, but other libraries may have other concerns. Especially when you work with hardware, where you will mostly get unsigned data types of various lengths. Once you start storing things, then you have to think harder - you could cut your filesize in half by switching down to floats from doubles, for ex. Yes, for local variables - who cares. But what happens when you have meshes, and arrays of millions of entries? Then you find that your little optimizations go a long way.

Share this post


Link to post
Share on other sites
assuming C++;

I''m pretty sure they are defined like this in the standard.

char <= short <= int
float <= double

on x86, ints and floats are usually 32 bits... which makes them easier to use by the (32 bits) cpu, and I advise you to prefer those over the others.

However, space might be a issue, as in:

int employeesAge[100000000000] //Big company but hey you get it.

Much memory would be saved by making those shorts, since they shouldn''t be higher than 80 in the worst case.


Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!