Smallest Variable Type

BlitzMax Forums/BlitzMax Programming/Smallest Variable Type

BLaBZ(Posted 2011) [#1]
What's the smallest variable type blitzmax has? What would you use to hold true or false? as in a bit or bool?


GfK(Posted 2011) [#2]
A byte is the smallest, though you can effectively store eight True/False flags in a single byte by setting individual bits to 1 or 0.


H&K(Posted 2011) [#3]
I know Ive asked this Before, but I cannot remember the answer. Is a "word" the smallest.

Ie 32 bit on 32 bits, and 64 bit on 64 bits?

That is is a byte (8bits) stored as 4 in a word, or is each byte takeing 32 bits?
If its stored as four in 32 bits, does that mean each forth Byte is faster to access?


Yasha(Posted 2011) [#4]
does that mean each forth Byte is faster to access?


Often yes. I don't know how BlitzMax does things, but many (most?) compilers will actually allocate four bytes for a variable of Byte or char type for this reason, unless you specifically tell them to optimise for size instead of speed (memory is cheap... cycles are not).

BlitzMax only produces 32-bit apps though so it presumably won't align things to 64-bit boundaries.


col(Posted 2011) [#5]
Hiya,

I once wrote a z80 emulator which, as the original is an 8bit cpu, I used the :Byte to store everything. As a comparison I change all those :Bytes to use 32bit :Ints ( with a little more modifying to the code ) and it was significantly faster. It didn't make much difference on my machine as it already ran smooth, but on a friends older laptop, it did make a significant difference which made it ran smoothly. It was an OLD laptop though :D


xlsior(Posted 2011) [#6]
Mark has mentioned in the past that the Int datatype is the fastest / most efficient one to use in Blitz.

You can use :byte if you are need to shave of every bit of memory usage you can, but if the memory space is not a major concern than int will be faster.