I have an object model that I use to fill results from a query and that I then pass along to a gridview.
Something like this:
public class MyObjectModel
{
public int Variable1 {get;set;}
public int VariableN {get;set;}
}
Let’s say variable1 holds the value of a count and I know that the count will never get to become very large (ie. number of upcoming appointments for a certain day). For now, I’ve put these data types as int. Let’s say it’s safe to say that someone will book less than 255 appointments per day. Will changing the datatype from int to byte affect performance much? Is it worth the trouble?
Thanks
No, performance will not be affected much at all.
For each
intyou will be saving 3 bytes, or 6 in total for the specific example. Unless you have many millions of these, the savings in memory are very small.Not worth the trouble.
Edit:
Just to clarify – my answer is specifically about the example code. In many cases the choices will make a difference, but it is a matter of scale and will require performance testing to ensure correct results.
To answer @Filip’s comment – There is a difference between compiling an application to 64bit and selecting an isolated data type.