Related articles |
---|
Optimization tradeoffs (time vs. space) roy@phri.uucp (1988-08-01) |
Re: Optimization tradeoffs (time vs. space) markhall@pyramid.pyramid.com (1988-08-05) |
Re: Optimization tradeoffs (time vs. space) ames!coherent!dplatt@ncar.UCAR.EDU (1988-08-05) |
Re: Optimization tradeoffs (time vs. space) tekcrl.tek.com!willc@RELAY.CS.NET (Will Clinger) (1988-08-06) |
Re: Optimization tradeoffs (time vs. space) gbs@nsc.nsc.com (1988-08-08) |
Optimization tradeoffs (time vs. space) midkiff@uicsrd.csrd.uiuc.edu (1988-08-09) |
Re: Optimization tradeoffs (time vs. space) roy@phri.uucp (1988-08-10) |
Re: Optimization tradeoffs (time vs. space) mmengel@cuuxb.ATT.COM (1988-08-11) |
From: | mmengel@cuuxb.ATT.COM (~XT4103000~Marc Mengel~C25~G25~6184~) |
Newsgroups: | comp.compilers |
Date: | 11 Aug 88 15:30:36 GMT |
References: | <1853@ima.ISC.COM> |
Organization: | AT&T, Data Systems Group, Lisle, IL |
In article <1853@ima.ISC.COM> roy@phri.uucp (Roy Smith) writes:
>
> Some compilers have options to select what kind of optimization to
>do: space or time. Can somebody give me some idea of how much difference
>it makes which you pick?
Well, take for example:
struct foo { char c; struct foo *next } *p;
while( p ){
putchar( p->c);
p = p->next;
}
To optimize for space on longword aligned machines, you would pack the
structure into 5 bytes, and have to unpack the structure to do the
p = p->next each time. However, it would nearly halve the space used
by a list of n characters. The unpack is probably twice as slow as
if the structure had the next pointer aligned.
For even more fun a complier *could* apply a data-compression algorithm
to large tables, arrays etc. and then de-compress when the array is
referenced/changed. I've never seen this done in a compiler.
You can actually save a lot of space in programs like compilers, etc.
by packing the structures. Very few compilers perform this kind of
optimization (Pascal compilers that implement "packed" for example),
since one can generally write their own pack/unpack routines if space
is really critical, and it is often a *serious* performance hit when
dealing with fields of structures.
--
Marc Mengel
attmail!mmengel
{lll-crg|mtune|ihnp4}!cuuxb!mmengel
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.