Page 1 of 3 123 LastLast
Results 1 to 10 of 24

Thread: Like a midget at a urinal, I would have to be on my toes

  1. #1

    Like a midget at a urinal, I would have to be on my toes

    This thread is about exe size. What's the smallest win32 (not console!) app that you've managed to produce and how did you do it?

    I'm interested in l33t 64K intros , so every K counts here. You may be surprised at the exe size I'll present here. It's not the smallest though. I'd have to be hardcore to get smaller.

    5.5K for a fully functional win32 app. Yep. I can go even smaller too if I manage to recompile the RTL (which will be one hell of a feat given that I only have the personal edition without source...). I have ideas on that, which will result in a *very very* small app. However, first I'd like to hear your values so far. What size is yours? ops:
    "All paid jobs absorb and degrade the mind."
    <br />-- Aristotle

  2. #2

    Like a midget at a urinal, I would have to be on my toes

    I have very little experience in this sort of thing, but as I'm the only one here at the moment I'll reply!

    I had no idea you could make a win32 app so small, how do you go about doing that? I suppose the smallest app I ever made would have been on my ZX81 about 20 years ago but that doesn't count really

  3. #3

    Like a midget at a urinal, I would have to be on my toes

    I'm using Delphi 6 Personal Edition here.

    Okay, a step by step guide for doing this...

    1) Start a new project
    2) Remove the form ("remove file from project")
    3) Go the the project menu and select "view source" (side note: does anyone else wonder why this wasn't View->Project Source instead? Just me? Oh well... :? )
    4) You're left sitting at the project source itself (the .dpr file). This is the file that usually means "hands off". However, it's the best way to get tiny exes - ignore the VCL and use direct Win32 stuff. Yucky, but the size makes up for it.
    5) Save your project somewhere. Compile it. Notice how this minimal app takes up *351K*!
    6) We don't want any VCL stuff - which means no "uses forms". Oh well, back to our Pascal roots, I guess. The .dpr file can be laid out like this:

    [pascal]program Project1; // name depends on what you saved it as

    begin

    end.[/pascal]

    I got rid of the "uses forms" bit there, since that's including VCL stuff. The other bits about "application.initialize" and "application.run" are VCL things too. Now we have a skeleton app with absolutely no functionality. Gee, ain't that useful . On the plus side, it's down to 8K from 351K(!!).

    I got rid of the {$R *.RES}, which includes the icon. This is about 1/2 a K of unnecessary stuff.

    Now, the main challenge is to turn this into a working win32 program. This takes a bit of savvy, unfortunately, and especially so if you're used to the comfy VCL. I've got a tutorial on this, pimp pimp, over at my site: thisaways

    We want to get a Window Class, register it, create a window, write a message loop (PeekMessage/DispatchMessage) and a window proc to handle some messages. Eesh!

    I solved this by copying and pasting function prototypes from the windows.pas and messages.pas (I have the VCL from Delphi 5, but its compiler generates *much* larger win32 exes. D6 is a lot leaner in this respect, though you wouldn't expect as much from the increased VCL program size. I've not tried D7 yet).

    My sizetest unit has *no uses clause at all*! Thus, I had to copy over the definitions of each required win32 function. These boiled down to simple declarations of dll functions, e.g.

    [pascal]procedure PostQuitMessage(nExitCode: Integer); stdcall; external 'user32.dll';[/pascal]

    With care, I managed to get an win32 window up and running... in 8K(!). That's the same value as the empty unit, btw. *Cough cough*.

    Now, I'm not done yet. There's a lovely exe packer that everyone must know about if interested in tiny exes: UPX. I ran this over my exe and the result is currently sitting at 5.5K.

    Note, though... if an empty app sits at 8K, and my thing ended up at 8K, then there must be some reason for the extra bloat such that adding more functionality doesn't change the exe size.

    The trick is this: even though no extra units were included, Delphi includes some anyway! There are two relevant files, System.pas and SysInit.pas, which form the RTL (run-time library). Ever wondered where the default Input/Output console vars come from? The files are set up in there. Ever wonder where the HInstance parameter is set up? In there.

    The RTL contains a bunch of crap that I don't need. Unfortunately, this is where I'm sitting at just now. I don't have the VCL source code for Delphi 6, which means that I can't create 'dummy' units for those two with nothing in them. If I try (compiling at the command line using 'dcc32.exe') then it lies, saying it can't find the .pas files (even if I create dummy ones).

    I've tried modifying the compiled .dcu units without luck - if I had the VCL source for D6 then I'd be all set, dammit. Oh well - 5.5K is good enough for now .
    "All paid jobs absorb and degrade the mind."
    <br />-- Aristotle

  4. #4

    Like a midget at a urinal, I would have to be on my toes

    So that's how it's done, cool. 351K seems a lot for a minimal app, can't say I'd noticed til now. My game demo exe is less than 700K and does a lot more than display a blank form. Now if you can get that exe down to less than 1K I'll be impressed

  5. #5

    Like a midget at a urinal, I would have to be on my toes

    I could compress it down easily enough - arrange it so that for the bits, all the 0s are consecutive, then all the 1s. Write the count of each and you'll be left with about 16 bytes of data. Of course, I'll leave decompressing that up to you :roll:

    I pimped this over at gamedev in a closed thread, but here it is again: the latest tech in 4K intros. This would probably be done entirely in assembly. Cool stuff!
    "All paid jobs absorb and degrade the mind."
    <br />-- Aristotle

  6. #6

    Like a midget at a urinal, I would have to be on my toes

    I have a working OpenGL app that currently sits at 15KB non-compressed. It contains drastically cut-down versions of GL.pas, GLU.pas and Windows.pas.

  7. #7

    Like a midget at a urinal, I would have to be on my toes

    Have you still not got around to doing that 64K intro yet, Sly? Yep, I saw that post on the borland.public.delphi.graphics newsgroup ages ago where you said you would do one in OpenGL ^._.^

    Btw, important notice about size: avoid "String"s, believe it or not, because including them causes lots of miscellaneous junk to be chucked in. The same goes for other memory functions, IIRC. Including an unused string variable in my test app caused the size to increase from 8K to 13.5K instantly (both uncompressed).

    Also, avoid the math unit. Its inclusion can bump up the size a fair bit and the most interesting stuff is in "system" anyway (i.e., sin and cos).
    "All paid jobs absorb and degrade the mind."
    <br />-- Aristotle

  8. #8

    Like a midget at a urinal, I would have to be on my toes

    How about PChars do they absorb less memory than a string ?
    Do it by the book, but be the author!
    <br />
    <br />Visit the Lion Productions website at:
    <br />http://lionprod.f2o.org

  9. #9

    Like a midget at a urinal, I would have to be on my toes

    TheLion, I'll confirm (or otherwise) that idea later on. I only have Delphi 5 here at work, where it doesn't matter (the exes produced end up 16K regardless). I'd imagine that PChars, char arrays ("array[0..255] of char") or ShortStrings would be quite good for size, but you'll have to wait for confirmation, unfortunately. ShortStrings get implicitly converted into Strings, you see, so I can't say for sure with those.

    Also, I have to investigate alternative to the usual memory managers. I guess you could use HeapAlloc/HeapFree (assuming I remember the names right!) from Win32.

    Incidentally, has anyone played around with size + Delphi7 yet?
    "All paid jobs absorb and degrade the mind."
    <br />-- Aristotle

  10. #10

    Like a midget at a urinal, I would have to be on my toes

    i have managed to produce a 9.1kb small executable (compressed by upx) with directxgraphics header. but maybe with the tricks of alimonster i can get it even smaller.
    http://www.martinpyka.de

Page 1 of 3 123 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •