P persianpowerman1 Active Member Licensed User Longtime User Oct 31, 2013 #1 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
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 Oct 31, 2013 #2 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: Code: Copy Dim b As Byte b = Asc("é") - 128 Log(Chr(b + 128)) Last edited: Oct 31, 2013 Upvote 0
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: Code: Copy Dim b As Byte b = Asc("é") - 128 Log(Chr(b + 128))
Erel B4X founder Staff member Licensed User Longtime User Oct 31, 2013 #3 How many such characters / numbers do you want to store? If I understand correctly you need one character and one number. If you choose String and Int it will take about 10 bytes. If you choose Character and Byte it will be 2-3 bytes. Is there any benefit from saving 7 bytes? No. A single image that you are loading can easily take 500,000 bytes. http://shreevatsa.wordpress.com/2008/05/16/premature-optimization-is-the-root-of-all-evil/ Upvote 0
How many such characters / numbers do you want to store? If I understand correctly you need one character and one number. If you choose String and Int it will take about 10 bytes. If you choose Character and Byte it will be 2-3 bytes. Is there any benefit from saving 7 bytes? No. A single image that you are loading can easily take 500,000 bytes. http://shreevatsa.wordpress.com/2008/05/16/premature-optimization-is-the-root-of-all-evil/
P persianpowerman1 Active Member Licensed User Longtime User Oct 31, 2013 #4 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
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