byte VS int in ZGE

All topics about ZGameEditor goes here.

Moderator: Moderators

Post Reply
User avatar
Ats
Posts: 603
Joined: Fri Sep 28, 2012 10:05 am
Contact:

byte VS int in ZGE

Post 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?
User avatar
Kjell
Posts: 1876
Joined: Sat Feb 23, 2008 11:15 pm

Re: byte VS int in ZGE

Post 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
User avatar
VilleK
Site Admin
Posts: 2274
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: byte VS int in ZGE

Post 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).
User avatar
Ats
Posts: 603
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Re: byte VS int in ZGE

Post by Ats »

Ok, thanks for the tips :D
Post Reply