![]() |
|
![]() |
Hi. I had some free days this month and decided (amongst firing up my studio) to look deeper at some of the more difficult OS/2 stuff. I covered EAs and am looking at hooks right now. Intriguing matter. Although I really don't understand why the EA stuff has to be so complex. I used EAs in Smalled, but that was coded over a year ago and I've found that I've lost most of my knowledge about it. Hooks are another matter. Hooks allow you to interfere with the way the system operates. It enables you to intercept messages from programs, capture keyboard input before it is sent to a program etc. I've decided to do something more with hooks. (They are used by SmallHtm to work with MLE editors.) I'll keep you all posted on the projects that may evolve from this.
Last month when we rounded up the calculator sample application I promised to take a look at smaller code. One of the things I hate are bloated programs. Large program blobs are becoming more and more like a normal thing. Simply take a look at a run of the mill word processor: It's eating megabytes of your hard drive and can be tediously slow on a 486 to a Pentium 133. But even the shareware and freeware programs are becoming larger and larger too. Where is this large code coming from? Well there are some causes:
Well most of this is obvious. (I left out obvious causes as leaving debugging code or debuggers info in your exe.) What can we do to make code as small and effective? Well here are some pointers I always use. In my experience these points usually pay off. Since this column isn't intended to be very technical I try to keep things as simple as possible.
The next points address more technical ways to write optimal code. Compilers and linkers have a number of switches on board that make them create smaller code. Besides that, code load may vary from compiler to compiler. So if you've got the time, try more compilers. At least one of them is free (as far as I know). The EMX compiler. (check out hobbes for this package).
Most compilers let you choose if your code has to be optimized for 386/486 or Pentium. Since the Pentium is optimized for code that is built in a RISC like manner (simple one word instructions), the code for a Pentium will, in general, be bulkier. The 386/486 code will use a lot of instructions that do more work per-instruction. So this code will be smaller, but not as fast. In a lot of cases we are not really interested in speed of a program. For example the Calculator. I doubt it very much if anyone would notice the speed change between these two compiler settings.
RC -x prog.rc prog.exe
Warp (since version 3.0) has even better compression. An "x2" has been added since then. The drawback for this is that the executables can only run on a OS/2 warp system. OS/2 2.x can't execute exepack 2 programs. But compression is really something you should try. The results are rather dramatic (as we will see in a minute).
There are more techniques like using Wrapper functions and realigning code pages. We'll look at those some other time because they need a lot more explaining. Right now we'll take a look at the effects of some of the settings. As an example program I used the calculator we build last months.
First we compile the Calculator code with minimal settings and slowly build it up to the smallest possible version that is compressed, based etc. This testing is done with Borland C++ 2.0. So if you're using another compiler this might vary.
1) Normal 38416 bytes 2) Based 34832 bytes 3) Based and x1 compression 33296 bytes 4) Based and x2 compression 27664 bytesNow one last tip, and this is a great one. There is a tool out there written by Mike Ruddy. (check also EDM/2 3.6) It's called LXOPT. This tool contains the x1 and x2 compression as well as something this tool is unique in: code page aligning and elimination of dead code. This is really a great tool, besides that it's free. If LXOPT is used with the calculator is makes the executable even smaller:
5) LXOPT 25340 bytes.As you can see the total reduction is rather dramatic. The code shrank one third and with hardly any effort on our side. For larger executables this effect is even more dramatic. So at least use Based and "x" compression. Although I would advise everybody to check on LXOPT and, of course, use good programming techniques.
That's it for this month.
LXOPT 1.22
Eric Slaats holds a degree in Computer Science and teaches computer technology in Eindhoven. He is the creator of the Smalled utilities.
![]() |
![]() |
![]() |
![]() |
Copyright © 1998 - Falcon Networking | ISSN 1203-5696 |