Archived

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

Endemoniada

char in place of int ?

Recommended Posts

Endemoniada    430
Hi guys, A lot of times I have a state that can take on a few values (2 to 8 say.) Is it better to use a char (I actually use BYTE) than an int ? Like this: BYTE cur_state; if(cur_state == 0) do some stuff... else if(cur_state == 1) do some stuff... ... ... Is seems like if they are only for if...else tests they would be better, but if they are for arithmetic they might not be as good as ints, like this: BYTE move_offset; int cur_offset; int offset=cur_offset + move_offset; because then I''m mixing types. It may seem like I''m anally micro-optimizing but they are for particles and I have thousands of structs active at any given time so I may as well do it the best way. What do you guys think ? Endo

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
In fact, since modern processors are 32-bit (or more!), its no more efficient, except it may even be more inefficient, to use a byte. Lots of use of bytes rather than words might save you kilobyte or two off the executable, a few kilobytes from RAM usage.. but it could cause you lots of headaches with overflows etc...

Share this post


Link to post
Share on other sites