www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/02/28/20:57:13

From: Shawn Hargreaves <Shawn AT talula DOT demon DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Trimming program size
Date: Fri, 28 Feb 1997 23:15:56 +0000
Organization: None
Distribution: world
Message-ID: <TojHdPBsc2FzEw9q@talula.demon.co.uk>
References: <01bc2468$540f0340$8c081ecb AT sly>
<19970227 DOT 220001 DOT 7167 DOT 0 DOT fwec AT juno DOT com>
<19970227 DOT 211926 DOT 4943 DOT 2 DOT chambersb AT juno DOT com>
NNTP-Posting-Host: talula.demon.co.uk
MIME-Version: 1.0
Lines: 45
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Benjamin D Chambers writes:
>>"Sly" <sly AT aussie DOT net> writes: 
>> I am (slowly) developing a game using the Allegro library.  I was 
>> wondering whether it would be possible to be able to trim the library
>> when the program is ready for general distribution.  That is, remove 
>> any unused sections, like video card specific drivers (my program 
>> just uses Mode-X resolutions) and any other sections not required.  
>> Would this be advantageous, or just too difficult to contemplate?
>
>I thought the linker already did this for you - as in, any object files
>in a library that go unreferenced are unlinked (however, all it takes is
>a single reference and the entire object file is linked in).  Somebody
>correct me if I'm wrong.

You're right. But in Allegro's case, the linker doesen't do an
especially good job of leaving things out, since there are a lot of
interconnections between different parts of the library.

In Allegro 2.1, lots of unnecessary stuff was getting linked into all
executables. I've improved that quite a bit in 2.2, but some redundant
code is unavoidable due to the way the vtables are used for drawing onto
different types of bitmap (pointers to all the basic drawing functions
are stored in the vtable, so all these functions will be included in
your exe even if you don't call them).

At present, linking works more or less on a module-by-module basis. If
you don't use any sound code, or don't use the keyboard handler, they
aren't included. Likewise the more obscure graphics functions (polygons,
3d code, floodfill, etc), are left out if they are unused. But the basic
geometric primitives, blitting and sprite drawing code, and all the
graphics drivers, will be linked into your exe.

It's easy to leave out graphics drivers: just edit the table at the top
of graphics.c and remove the ones you don't want. If you are only using
mode-X screens, and not drawing onto any memory bitmaps, you could also
leave out a lot of the linear graphics code by replacing functions in
the _linear_vtable (defined in graphics.c) with NULL, but that will
cause the thing to crash if you then call any of the functions that have
been removed...


/*
 *  Shawn Hargreaves - shawn AT talula DOT demon DOT co DOT uk - http://www.talula.demon.co.uk/
 *  Beauty is a French phonetic corruption of a short cloth neck ornament.
 */

- Raw text -


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