Answer the question
In order to leave comments, you need to log in
Does it make sense to use byte if the operation converts to int??
Hello.
Technical question. Mobile games.
Let's say to optimize memory consumption, I want to use byte instead of int (the number will not be more than 255). But is there any point if byte is converted to int in comparisons and calculations (I read that it takes time to convert).
That is, on the one hand, memory savings (small) are obtained, on the other, constant conversion ????? Did they fall from the oak tree?
byte a;
byte b;
if (a < b) {
}
if (a == b) {
}
Answer the question
In order to leave comments, you need to log in
Reducing the size of variables is only worth it if you store them somewhere in the database, on a hard one, and this data can grow well. If everything works in memory, then there really is no point in such a conversion, for the machine the most convenient type to work with is int, and it will implicitly cast most primitive types to it. Indeed, there are recommendations not to use the types shot, ushot, etc. unnecessarily, because internally they are all the same converted to int.
In addition, a couple of links: here and here
And a quote from them
It should be noted that in C# all arithmetic expressions are made on int. This means that you will need to increase the number of bytes to type int in order to perform calculations on them
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question