Forum > OpenGL

Comparing Windows C OpenGL App Size(46KB) to FreePascal OpenGL App(54KB), Why?

(1/2) > >>

d-_-b:
I believe the code in triangle.c and triangle.pas kind of does the same thing.

But if I compile the c file gcc -o triangle.exe triangle.c -lopengl32 -lgdi32 the exe is 46KB,

Where if I compile the pas file fpc -CX -XX -Xs -XXs triangle.pas the exe is 139KB, (EDIT: See patch below to drop exe to 54KB)

Why?

Fibonacci:
Because gl uses SysUtils which is pretty heavy. FPC has its own implementation for everything, C uses libc provided by the OS.


If you comment out few lines from the gl unit (uses sysutils + uses math + few exceptions + SetExceptionMask) you will get 68 KB executable.

d-_-b:

--- Quote from: Fibonacci on March 23, 2024, 07:00:50 pm ---If you comment out few lines from the gl unit (uses sysutils + uses math + few exceptions + SetExceptionMask) you will get 68 KB executable.

--- End quote ---

Sweet thanks, i patched gl.pp and can confirm the exe is now 68kb.

Now I wonder how much does the windows unit take of the remaining 22KB?

I was busy stripping the windows unit out by hand but it was a bit to much, now i wonder how hard it would be to code something. I cannot just grep windows.pp because it uses a lot of $inc, i wonder if there is a cli command that will give me the full windows.pas so that i can just grep that? mmm,

Fibonacci:
If you remove the Windows unit you will cut approx 2 KB. The GL unit takes about 20 KB (of which strings alone take up ~5 KB, the code ~14 KB). The heaviest is now the RTL (40+ KB), you could strip it down to ~10 KB (preserving some functionality) or to ~5 KB absolute minimal RTL - it would work in this case, but would be very trublesome as the code grows. Not worth the hassle.

d-_-b:
Thanks for the information, I don't know why I did not use file to check the binaries but only once I opened them in Ghidra did i realise i was compare 32-bit to 64-bit(Doh!).

Below a list of 32-bit and 64-bit built binaries and their size


45KB c-triangle32.exe   : PE32 executable (console) Intel 80386, for MS Windows, 13 sections
54KB pas-triangle32.exe : PE32 executable (console) Intel 80386 (stripped to external PDB), for MS Windows, 6 sections
145KB c-triangle64.exe   : PE32+ executable (console) x86-64, for MS Windows, 20 sections
68KB pas-triangle64.exe : PE32+ executable (console) x86-64 (stripped to external PDB), for MS Windows, 7 sections


Now there only 9 Bits difference between the 32 bit versions, and strangely the 64bit version seems to be better for fpc?!

Navigation

[0] Message Index

[#] Next page

Go to full version