Page 1 of 1

byte VS int in ZGE

Posted: Fri Jan 25, 2019 10:56 am
by Ats
Hi guys, just a quick question:
I'm using a lot of const/var byte and I just read somewhere that int performs slightly better because it is already aligned for native CPU instructions. And byte should only be used to store values between -128 and 127.
Is that the case for ZGameEditor?

Re: byte VS int in ZGE

Posted: Fri Jan 25, 2019 12:46 pm
by Kjell
Hi Ats,
Ats wrote: Fri Jan 25, 2019 10:56 amI'm using a lot of const/var byte and I just read somewhere that int performs slightly better because it is already aligned for native CPU instructions.
Completely depends on the circumstances & instructions involved, but in general you shouldn't be able to notice any difference.
Ats wrote: Fri Jan 25, 2019 10:56 amAnd byte should only be used to store values between -128 and 127.
Bytes in ZGE are unsigned, so they range from 0 to 255. Also, keep in mind that bytes aren't really bytes when you use them as local variables ( at the moment ).

Code: Select all

byte foo = 999; // Outside 0-255 range
trace(intToStr(foo)); // Still outputs 999
K

Re: byte VS int in ZGE

Posted: Fri Jan 25, 2019 1:54 pm
by VilleK
Use int everywhere is general good advice. Only thing to consider if you are creating huge arrays, then using byte if possible will save memory.

Indeed like Kjell points out byte range is not enforced on local variables (only when stored to global variable or array is it truncated to 0..255 range).

Re: byte VS int in ZGE

Posted: Fri Jan 25, 2019 1:56 pm
by Ats
Ok, thanks for the tips :D