Android Question smallest variables to save memory?

persianpowerman1

Active Member
Licensed User
Longtime User
hey guys... all i need to do is save a single letter in a variable... and save a single number in another...

is char the best use for that since string is quite big?
similarly...
is byte the best use for that since INT is quite big?

eg.
dim flag as char
char = "u"

.... the max i would only require to save is 1 alphabet...whats the most efficient way to handle this???
... the max number i would go till is 0 to 120... whats the most efficient way to handle this???

YO!han
 

Informatix

Expert
Licensed User
Longtime User
Byte (-128...127) = 8 bits
Char (Unicode) = 16 bits
so the winner is Byte for 255 different characters. Characters can be converted to bytes with the Asc function. Example:
B4X:
Dim b As Byte
b = Asc("é") - 128
Log(Chr(b + 128))
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

persianpowerman1

Active Member
Licensed User
Longtime User
yeah thanx..
erel that made a lot of sense. . i read the entire article.. and it was so true.. dont need to waste time about the efficiency of non critical code...
thanx again
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…