Procedures cut exe size?

Everything else that doesn't fall into one of the other PB categories.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8453
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Procedures cut exe size?

Post by netmaestro »

I had an interesting thing happen today. I have a program that is around 400 lines with a datasection containing about 30k or so of graphics. The structure of the program was all inline code with If-ElseIf-ElseIf-ElseIf-Endif to choose which code to run based on the mode found in the program parameters. It compiled to around 147k for the exe size. Once I was happy with the way the code ran, I restructured the program so that each of the code sections was in its own procedure and all the If-ElseIf block did was choose which procedure to run and then end. The code itself changed very little, nothing significant was removed. But after the restructure, the compiled exe size went down to 115k from 147.

Has anyone else noticed similar? And if this is something to be expected, can someone shed some light on why? I'm flummoxed as to why this would be.
BERESHEIT
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Re: Procedures cut exe size?

Post by MachineCode »

Without seeing the code, it sounds like the procedures are replacing many repetitions of (small?) blocks of code, and therefore obviously the executable would become smaller. But only you know if that's the case, since you can see the code.
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8453
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Procedures cut exe size?

Post by netmaestro »

No, the blocks only execute once. There's loops in them but the loops are in the procs too.
BERESHEIT
User avatar
J. Baker
Addict
Addict
Posts: 2196
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: Procedures cut exe size?

Post by J. Baker »

That's interesting. I'll have to do my own test sometime and see what results I get. I usually use procedures anyway. But if what you are saying works for all code, then that could be helpful.
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef


Even the vine knows it surroundings but the man with eyes does not.
Post Reply