Pesky Ints!

BlitzMax Forums/BlitzMax Programming/Pesky Ints!

Skorne(Posted 2009) [#1]
Hi folks can anyone explain to me why everyone uses ints instead of shorts for things that clearly aren't going to have values more than 65k? Surely it's just bad practice making your app need more memory than it should?

A good example is say MouseX and MouseY... unless we are living in the year 2050 with 100k screen resolutions nobody is ever going to have a mouse coord that high.

That said my question is what's the best way to convert from an int to a short?


Gabriel(Posted 2009) [#2]
Hi folks can anyone explain to me why everyone uses ints instead of shorts for things that clearly aren't going to have values more than 65k?

Because Ints are faster than Shorts.

unless we are living in the year 2050 with 100k screen resolutions nobody is ever going to have a mouse coord that high.

Equally, unless we're in the year 1950, 4 wasted bytes for storing the mouse coordinates are not going to put much of a dent in even the oldest of computers with the least memory going.

That said my question is what's the best way to convert from an int to a short?

In what way convert? I would normally expect you to ust assign one to the other, exactly as if both were shorts or both were ints. This will effectively just drop the high 2 bytes.


Skorne(Posted 2009) [#3]
Thanks for the quick reply, I didn't know ints were faster than shorts. sounds like it might be better just to use ints throughout my code where I've been using shorts.


Zeke(Posted 2009) [#4]
small speedtest:



xlsior(Posted 2009) [#5]
Average of several runs on standard BlitzMax:

short array: 451
int array : 261
long array : 713


Average of several runs on custom BlitzMax with modules compiled for speed instead of filesize:

short array: 430
int array : 258
long array : 609