22
\$\begingroup\$

Create short source code in your favourite compiled language that compiles into a big (not less than 104857600 bytes) executable file. The program must be runnable (assuming 1GB of free memory) and can do anything (preferrable something simple like a hello world).

Usage of non-obvious tricks is encouraged.

Boring example in C:

int a[1024*1024*25] = { 1 };

int main(){}

Bonus points if it can be "explained" why the executable can't be reduced in size (i.e. all bloat is actually used somehow).

\$\endgroup\$

closed as off-topic by cat, Mego, Denker, Blue, Rɪᴋᴇʀ Apr 19 '16 at 14:27

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions without an objective primary winning criterion are off-topic, as they make it impossible to indisputably decide which entry should win." – cat, Mego, Denker, Blue, Rɪᴋᴇʀ
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 7
    \$\begingroup\$ Statically link ALL the libraries! \$\endgroup\$ – marinus Dec 18 '13 at 20:40
  • \$\begingroup\$ That's why initially thought about 10+ MiB, but revised to 100+... Or it means all libraries in the system? \$\endgroup\$ – Vi. Dec 18 '13 at 20:45
  • \$\begingroup\$ Can a HTML file be considered as an executable? \$\endgroup\$ – xem Dec 21 '13 at 19:07
  • \$\begingroup\$ Unlikely.󠀠󠀠󠀠 \$\endgroup\$ – Vi. Dec 22 '13 at 1:29
  • \$\begingroup\$ This could stay on-topic if the winning criterion was changed to "largest output file" or something, but that would invalidate the current answers and make this a duplicate of at least one other challenge. See The state of the popularity contest tag \$\endgroup\$ – cat Apr 18 '16 at 21:37
13
\$\begingroup\$

OK, here's another one in C, going for the vaguely defined bonus points:

#define a(x) x,x|1,x|2,x|3,x|4,x|5,x|6,x|7
#define b(x) a(x),a(x|8),a(x|16),a(x|24)
#define c(x) b(x),b(x|32),b(x|64),b(x|96)
#define d(x) c(x),c(x|128),c(x|256),c(x|384)
#define e(x) d(x),d(x|512),d(x|4<<8),d(x|6<<8)
#define f(x) e(x),e(x|2048),e(x|4096),e(x|6144)
#define g(x) f(x),f(x|8192),f(x|4<<12),f(x|6<<12)
#define h(x) g(x),g(x|2<<14),g(x|4<<14),g(x|6<<14)
#define i(x) h(x),h(x|2<<16),h(x|4<<16),h(x|6<<16)
#define j(x) i(x),i(x|2<<18),i(x|4<<18),i(x|6<<18)
#define k(x) j(x),j(x|2<<20),j(x|4<<20),j(x|6<<20)
int u,v,z[]={k(0),k(2<<22),k(4<<22),k(6<<22)}
int main(){for(u=v=0;u<1<<25;u++)v|=u!=z[u];return v;}

Basically, at compile time, it build a ascending sequence of integers from 0 to 225 − 1. At runtime, it verifies that the sequence indeed contains the expected values, and if not, returns a non-zero error code.

Ps. If I did my math right, the executable should be over 100 MiB. I'll let you know the exact size once it's done compiling...

\$\endgroup\$
  • 1
    \$\begingroup\$ Ps. My attempts to verify the actual size have been (hopefully temporarily) stymied by what I suspect to be a rather unusual GCC error message: virtual memory exhausted: Cannot allocate memory. o_O Will try to tweak options to see if I can get it to compile somehow. \$\endgroup\$ – Ilmari Karonen Dec 19 '13 at 16:34
  • 12
    \$\begingroup\$ Aww, I was just picturing you standing on a rolling chair and having a sword fight with another developer. \$\endgroup\$ – Iszi Dec 19 '13 at 18:16
  • \$\begingroup\$ Also can't build with clang (ICE) and tcc. \$\endgroup\$ – Vi. Dec 20 '13 at 14:43
  • 1
    \$\begingroup\$ Turn off all optimization (-O0) to minimize the demands on the compiler, and enabling pipes (-pipe) might or might not help. \$\endgroup\$ – dmckee Dec 21 '13 at 2:35
  • 3
    \$\begingroup\$ That compiling problem reminds of a winning entry of IOCCC who write his own preprocessor to verify that the program was correct: ioccc.org/2004/vik2.hint \$\endgroup\$ – Christian Semrau Dec 22 '13 at 10:03
6
\$\begingroup\$

C#

Not sure if this qualifies as short, because the source code ended up being >30k :)

I.e - too big to quote. Here's a slightly shortened version of it

using System.Collections.Generic;
class Program
{
    static void Main()
    {
        var a = new List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<List<int>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>();
    }
}

The code I actually compiled can be found here: http://pastebin.com/R5T3e3J0

This will create a .EXE file of ~45KiB when compiled without optimizations. Compile it again with Ngen.exe (Native Image Generator) and it becomes a whopping 104MiB!

This works due to how the CLR generic type system works. Each and every List<> in the above code will generate a new type declaration (normally through JIT compilation, but Ngen performs AOT compilation). So one type for List< int >, another for List< List< int > >, and so on. So for this code, a total of 5160 different generic lists will be created.

\$\endgroup\$
  • 1
    \$\begingroup\$ What you need is a script that will write your program. \$\endgroup\$ – hildred Dec 29 '13 at 15:28
  • \$\begingroup\$ It's rather trivial to reduce the size of the program (by removing nesting levels of List). Can it be made so that you can't easily remove the repeating code without affecting program function? \$\endgroup\$ – Vi. Dec 29 '13 at 22:56
  • \$\begingroup\$ Well of course you can just remove the nesting, but likewise, in the C example you could just remove a few #defines and make the program smaller. The way I interpreted the requirement that it can't be reduced in size, was that it can't be optimized away. If you're allowed to just modify the source code I don't quite see the point. :) \$\endgroup\$ – Christian Palmstierna Dec 30 '13 at 9:58
  • 1
    \$\begingroup\$ Although it should be noted that this can probably be optimized away, since the variable a is never used. \$\endgroup\$ – Christian Palmstierna Dec 30 '13 at 10:00
4
\$\begingroup\$

COBOL

   ID DIVISION. 
   PROGRAM-ID. BLOAT. 
   ENVIRONMENT DIVISION. 
   DATA DIVISION. 
   WORKING-STORAGE SECTION. 
   01  THE-TEST-STRINGS. 
       05  FILLER OCCURS 11584 TIMES. 
           10  TEST-STRING          PIC X(11584). 
   LOCAL-STORAGE SECTION. 
   01  FIRST-TIME-FLAG              PIC X VALUE "Y". 
   01  DISP-BEFORE-STRING     COMP  PIC 9(8). 
   01  LOOP-COUNTER           COMP  PIC 9(8). 
   01  START-STRING. 
       05  FILLER OCCURS 0 TO 11584 TIMES 
           DEPENDING ON DISP-BEFORE-STRING. 
           10  FILLER               PIC X. 
       05  THE-SUBSTRING            PIC X(12). 
   01  INITIAL-STRING               PIC X(12) 
                                     VALUE "HELLO WORLD!".
   LINKAGE SECTION. 
   01  STRING-PARAMETER             PIC X(11584). 
   01  THE-RESULT                   PIC X. 
   PROCEDURE DIVISION USING 
                                    STRING-PARAMETER 
                                    THE-RESULT 
                                    . 

       IF FIRST-TIME-FLAG = "Y" 
           PERFORM                  SET-UP-STRINGS 
       END-IF 
       PERFORM 
         VARYING                    LOOP-COUNTER 
         FROM                       1 
           BY                       1 
         UNTIL                      LOOP-COUNTER 
           GREATER THAN 11584 
         OR STRING-PARAMETER 
             EQUAL TO               TEST-STRING 
                                        ( LOOP-COUNTER ) 
       END-PERFORM 
       IF STRING-PARAMETER 
         EQUAL TO TEST-STRING ( LOOP-COUNTER ) 
           MOVE "Y"                TO THE-RESULT 
       ELSE 
           MOVE "N"                TO THE-RESULT 
       END-IF 
       GOBACK 
       . 
   SET-UP-STRINGS. 
       PERFORM 
         VARYING                    LOOP-COUNTER 
         FROM                       0 
           BY                       1 
         UNTIL                      LOOP-COUNTER 
           EQUAL TO 11584 
           MOVE 11584               TO DISP-BEFORE-STRING 
           MOVE SPACE               TO START-STRING 
           MOVE LOOP-COUNTER        TO DISP-BEFORE-STRING 
           MOVE INITIAL-STRING      TO THE-SUBSTRING 
           MOVE START-STRING        TO TEST-STRING 
                                        ( LOOP-COUNTER + 1 )
       END-PERFORM 
       MOVE "N"                     TO FIRST-TIME-FLAG 
       . 

A little knowledge can be a dangerous thing.

It can be faster to do one large compare than a lot of small compares; IBM's Enterprise COBOL (up to Version 4.2) can have a maximum WORKING-STORAGE of 128MB (Version 5.0 can have 2GB); LOCAL-STORAGE offers a further 128MB if you need more space.

The task is to confirm that a 11584-byte piece of storage has the value "HELLO WORLD!" somewhere, and the rest is space.

The, fictitious, programmer decides to write a sub-program for this (just in case it is needed elsewhere), and to include their high-performance technique (bonus).

The programmer calculates that 11584 * 11584 is 128MB, so uses WORKING-STORAGE for a huge table, and LOCAL-STORAGE for everything else that is needed.

The programmer codes it up, and smiles knowingly to themselves when the compile is clean. They were right about the 128MB.

Tests the code. It works. Possibly a little slow, but there's a heavy load on machine. Smiles again, thinking how slow it would be if coded without their level of expert knowledge.

The WORKING-STORAGE comes in at 134,189,056 bytes, and there's a good few bytes of other stuff as well. Should be large enough.

The reality is that doing a long compare instead of a short compare, as implemented here, is a very slow way to do it.

Even slower, the LOCAL-STORAGE, which is initialised by run-time routines every time a sub-program is called, causes the entire 128MB to be set up for each CALL.

The programmer was just plain wrong about the size of the table, there is enough room without using LOCAL-STORAGE. Long compares can beat short compares, but only when the actual number of compares is reduced.

I considered swapping the LOCAL-STORAGE and WORKING-STORAGE around, it is just far less likely someone would code it that way round, so I didn't. Putting a VALUE SPACE on the table (if it had been in LOCAL-STORAGE) would have initilised the table twice on each CALL, so even slower.

The Bloat can't be removed, without rewriting the program. Most of the code is bad, though there is one useful technique.

This is not a real-life example, but I can imagine someone doing it, if that someone is clever enough :-)

Compiling is no problem at all. Running it with every possibility quickly proves to be not worth attempting.

Of course, there is a plain old Bug as well. A very common one in "searching" tasks.

\$\endgroup\$
0
\$\begingroup\$

PowerBASIC

#BLOAT(104857600)
FUNCTION PBMAIN
  PRINT "Hello World"
  BEEP
END FUNCTION
\$\endgroup\$
  • \$\begingroup\$ It's comparable to the C example in the question. \$\endgroup\$ – Vi. Dec 29 '13 at 22:57
0
\$\begingroup\$

Scala

import scala.{specialized=>s}
import scala.Specializable.{Everything=>E}
class Printer[@s(E) A, @s(E) B, @s(E) C, @s(E) D, @s(E) E, @s(E) F, @s(E) G, @s(E) H]{
    def print(a:A,b:B,c:C)=println(s"$a, $b, $c")
}

object Main extends App{ 
    (new Printer[Int,Int,Int,Int,Int,Int,Int,Int]).print(1,2,3)
}

The specialized annotation creates a new class for each type in order to prevent boxing when the types eventually all get turned into objects. It will create 10^8 ((Everything consists of 10 types)^(8 type parameters on the class)) class files, each 300-500 bytes, if it doesn't crash first.


This could be explained by saying that performance is important, especially if the class actually did more than have a method to print. Using generic specialized methods instead of putting it all in the declaration would also make it harder to notice

\$\endgroup\$
  • \$\begingroup\$ Which scala version do I need to build this? 2.9.2+dfsg-1 does not like s"whatever" and don't know about scala.Specializable. \$\endgroup\$ – Vi. Dec 29 '13 at 23:00
  • \$\begingroup\$ Scala 2.10 includes the interpolated strings with s"", but you can remove that string without any effect on size. Scala 2.8 has the specialization feature, so if you remove the interpolated string, everything should work fine. \$\endgroup\$ – user60561 Dec 30 '13 at 15:21
-2
\$\begingroup\$

Javascript

function bigenough(){
        var kbytes = $('html').html().length;
        return (kbytes>1024*100);
}
while(!bigenough()){
$('html').append('<p>WASSUP</p>');}

Run this code in Browser Console on this page and when complete, save the page. it should result in a file size greater than 100 MB. Still testing. Will post actual size once done.

update-
the saved page is the result executable. The v8 engine of chrome is the compiler. And the code I posted is the program. i admit that it does take quiet a long to compile. :D

\$\endgroup\$
  • 1
    \$\begingroup\$ Doesn't work as required. The task is to create a executable file that is way too big, not one that consumes way too much memory when run. Also, overuse of jQuery. \$\endgroup\$ – John Dvorak Feb 17 '14 at 12:04
  • \$\begingroup\$ @JanDvorak it will create a HTML File with size greater than 100MB. Also the Question doesnot specify any JQuery usage limitations. The program is still executing on my Chrome and the page is consumning 300mb of memory as reported by the Chrome Task Manager. \$\endgroup\$ – rahulroy9202 Feb 17 '14 at 12:19
  • \$\begingroup\$ It won't. Every append you do happens purely in memory. It will only create an 100MB HTML file if the user triggers a save operation. Which he might not be able to do, nor want to. Also, even if you call this process of appending "compilation" and you manage to store the resulting HTML as a file, I don't think you're allowed to write your own compiler. \$\endgroup\$ – John Dvorak Feb 17 '14 at 12:24
  • \$\begingroup\$ @JanDvorak I have pointed out in the answer that the page must be saved. here, the page is the result executable. The v8 engine of chrome is the compiler. And the code I posted is the program. \$\endgroup\$ – rahulroy9202 Feb 17 '14 at 12:27
  • 2
    \$\begingroup\$ V8 is a compiler that produces a tiny "executable" (which never gets it to the hard drive) and executes it, which then proceeds on to generate a huge "source file" (in a language that isn't even compiled, nor a programming language). If you call the result of your script an executable (nope...) then we must call your script the compiler, not V8. It's not called compilation if your script gets executed in the process (macros kinda blur that line, but this isn't a macro) \$\endgroup\$ – John Dvorak Feb 17 '14 at 12:30

Not the answer you're looking for? Browse other questions tagged or ask your own question.