Mail Archives: djgpp/1997/04/30/09:21:52
Tom Grandgent wrote:
>
> I am working on a realtime game and have been wondering about
> ints vs. shorts. At first I used ints for everything, still being
> partially in the 16-bit mentality of things. Then I noticed that
> I could use shorts instead to save a lot of memory...
>
> I have heard that there is a performance difference between shorts
> and ints. If anyone could explain when and how much this matters,
> I would be very grateful. I'm just wondering whether to use ints
> for everything, shorts for everything, or a mix.
The difference is in the tradeoff between memory usage and speed, always
one of the banes of programmers. ;) In general, when working in any
computer architecture, the fastest and most efficient data size will be
the native word, i.e., the int. Shorts and longs are designed for
portability, to be used only when you know you need values of a certain
range.
If you have a program where size is not critical, and the range of
possible values for your variables isn't too large for a 16-bit integer,
then you should go ahead and use ints. If you need to have data of a
certain size, then go ahead and explicitly use shorts and longs. The
speed difference probably won't be all that noticeable, unless you get
into extremely CPU-intensive operations.
Also, remember that with DJGPP you have access to as much as 256 MB of
physical and virtual memory. Don't get too bogged down with saving
memory unless there's a good reason to. ;)
--
---------------------------------------------------------------------
| John M. Aldrich, aka Fighteer I | mailto:fighteer AT cs DOT com |
| Plan: To find ANYONE willing to | http://www.cs.com/fighteer |
| play Descent 2 on DWANGO! | Tagline: <this space for rent> |
---------------------------------------------------------------------
- Raw text -