www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/04/30/09:21:52

From: "John M. Aldrich" <fighteer AT cs DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: ints vs. shorts
Date: Wed, 30 Apr 1997 00:43:20 +0000
Organization: Two pounds of chaos and a pinch of salt
Lines: 36
Message-ID: <336695A8.4A5F@cs.com>
References: <3366B866 DOT 5466 AT canvaslink DOT com>
Reply-To: fighteer AT cs DOT com
NNTP-Posting-Host: ppp107.cs.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019