When you know that a value will be very small (single digit), wouldn't it make sense to use Int16 instead of Int32? It seems that the least amount of memory required for every variable would be preferable.

Recommended Answers

All 3 Replies

Your question really depends on the application you are using to really determine whether or not worrying about an int (singed/unsigned, 16/32/64) needs to be typed.

Are you minimizing memory for an embedded or mobile app? If so, paying attention to details like that can be important. Otherwise, just use the int, and free it up when your done.

commented: good advice +5

Also if you're using bitmasking it is very importanting to have a specific data type size. IE if you shift left the bits one place on a 32 versus a 64bit data type they will have very different results.

I wouldn't worry about using the smallest-possible-datatype for the most part. Modern computers typically have more than enough resources to handle the waste

Okay, thanks for the tips.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.