Recent

Author Topic: Comparing Windows C OpenGL App Size(46KB) to FreePascal OpenGL App(54KB), Why?  (Read 2091 times)

d-_-b

  • New Member
  • *
  • Posts: 48
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?
« Last Edit: March 23, 2024, 09:17:13 pm by d-_-b »
Code: Pascal  [Select][+][-]
  1. mov     ax,0013h
  2. int     10h
Denthor thanks for the vga programming tutorials | Download all tutorials

Fibonacci

  • Hero Member
  • *****
  • Posts: 643
  • Internal Error Hunter
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.
« Last Edit: March 23, 2024, 07:10:23 pm by Fibonacci »

d-_-b

  • New Member
  • *
  • Posts: 48
If you comment out few lines from the gl unit (uses sysutils + uses math + few exceptions + SetExceptionMask) you will get 68 KB executable.

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,
Code: Pascal  [Select][+][-]
  1. mov     ax,0013h
  2. int     10h
Denthor thanks for the vga programming tutorials | Download all tutorials

Fibonacci

  • Hero Member
  • *****
  • Posts: 643
  • Internal Error Hunter
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.
« Last Edit: March 23, 2024, 09:23:23 pm by Fibonacci »

d-_-b

  • New Member
  • *
  • Posts: 48
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?!
Code: Pascal  [Select][+][-]
  1. mov     ax,0013h
  2. int     10h
Denthor thanks for the vga programming tutorials | Download all tutorials

Fibonacci

  • Hero Member
  • *****
  • Posts: 643
  • Internal Error Hunter
You sure there is no debug info? This C exe should be much smaller. Try "strip triangle.exe".

d-_-b

  • New Member
  • *
  • Posts: 48
I stripped all of them and now the c 64bit binary is smaller, which i also found strange... because i was under the impression 64bit binaries is larger then 32bit binaries due to the word size?


 22K 22030 c-triangle32.exe:   PE32 executable (console) Intel 80386 (stripped to external PDB), for MS Windows, 8 sections
 21K 21504 c-triangle64.exe:   PE32+ executable (console) x86-64 (stripped to external PDB), for MS Windows, 11 sections
 54K 54784 pas-triangle32.exe: PE32 executable (console) Intel 80386 (stripped to external PDB), for MS Windows, 6 sections
 68K 69120 pas-triangle64.exe: PE32+ executable (console) x86-64 (stripped to external PDB), for MS Windows, 7 sections


Code: Pascal  [Select][+][-]
  1. mov     ax,0013h
  2. int     10h
Denthor thanks for the vga programming tutorials | Download all tutorials

Fibonacci

  • Hero Member
  • *****
  • Posts: 643
  • Internal Error Hunter
I stripped all of them and now the c 64bit binary is smaller, which i also found strange... because i was under the impression 64bit binaries is larger then 32bit binaries due to the word size?

Probably due to a different ABI (64 bits being more efficient). To be more precise: parameter passing in registers instead of on the stack. Eventually 64 bit version will become larger than 32 bit as you write more code (not just API calls).

 

TinyPortal © 2005-2018