Converting Variables

BlitzMax Forums/BlitzMax Programming/Converting Variables

Tachyon(Posted 2008) [#1]
I use INTs everywhere, but I like to save my variables as BYTEs whenever I can (assuming that the integer will never be above 255) to save space.

So I am assuming that:
Local dummy:int = ReadByte(filein)
'later in the code...
WriteByte(dummy,fileout)

...is this successfully converting the BYTE to an INT upon loading and saving.

I guess what I would like is reassurance that this isn't going to cause any long-term problems (mem leaks, slowdowns, etc.)


Dreamora(Posted 2008) [#2]
it converts them. problem is when you have something thats larger than a byte or negative, ...


Czar Flavius(Posted 2008) [#3]
What happens if you save an int that can't be converted to a byte.


Tachyon(Posted 2008) [#4]
I don't think I've ever done that. The only INTs I save as BYTEs are thousands of map and character variables that I know would never go below 0 or above 255. I built my RPG system around stats that generally have a range between 0-100.

The only reason I use them as INTs in the program is because numerous people (Mr. Sibly included) have remarked that BYTEs are slower than INTs during code execution, however BYTEs take up far less space once saved to disk.


Gabriel(Posted 2008) [#5]
Wouldn't it be easier and safer if you just wrote them as ints ( or even text ) and use ZLib to compress it? That way you're never going to change the content of a variable, forget that you're saving it as a byte and waste three hours going through great gobs of code looking for a bug only to remember that the variable should only ever have been 0-255.


Czar Flavius(Posted 2008) [#6]
Your character is a bit of a jerk. After upsetting a woman, he has an sudden urge to ask if he can look in her inventory.

http://basiliskgames.com/screen9.htm


Muttley(Posted 2008) [#7]
I think you're falling prey to premature optimisation there. ;)

Even if you've got 100000 int variables to store, the filesize would only be 390KB as apposed to 97.5 KB as bytes. In these days when you can buy a 500Gb drive for less than £60 I don't think you really need to worry about all that extra hassle just to save a miniscule amount of storage space.