Unused Methods
william chan
Posts: 1,326
Hi,
If a method in an object is unused, will the SPIN compiler exclude it from the final byte code to save space?
Thanks.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.fd.com.my
www.mercedes.com.my
If a method in an object is unused, will the SPIN compiler exclude it from the final byte code to save space?
Thanks.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.fd.com.my
www.mercedes.com.my
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Pull my finger!
That would save a lot of program space.
I mean for example if I were to include some Maths object, I probably will use only 40% of all the methods....
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.fd.com.my
www.mercedes.com.my
Unoptimised and the PropTool knows all three maths objects used are the same and only includes it once.
Optimised and the PropTool would have to include three optimised objects which may be up to three times larger than the single maths object.
There's no necessity to use objects as provided. The solution if you need to save space is to copy the object source into the project directory, rename the file and remove unwanted code, and use that instead.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Pull my finger!
-Phil
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'Still some PropSTICK Kit bare PCBs left!
Hum, can someone put it in plain bold for me. This is True , Guess , False
heres an example, a program I just compiled using F8 = 1947 longs for program. I assume variables (285 longs) doesn't take eeprom space.
Using PHil's clean I get a binary image of 1605 longs. i.e. ~18% reduction
There's almost no optimisation done by PropTool except not including the same objects used multiple times. Write "var := var" and the code for that will be there. For "if true" any else clause will be included. Add a "return" at the end of a method and there will be two consecutive returns in the bytecode.
Unused methods take up image space but that's not a problem if you have plenty of memory or don't care. Most people can probably ignore the issue and not have to worry about it.
They do. The Eeprom loads a full 32KB and that includes the variable space. Only the stack ( everything after code, DAT and variables ) isn't saved to the .binary file.
-Phil
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'Still some PropSTICK Kit bare PCBs left!
That is not a good solution if we want to improve on other's objects and return the improvements to obex.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.fd.com.my
www.mercedes.com.my
In which case your primary goal isn't to save space but to improve what there already is, and as you don't know what others will want to use in the improved object you cannot really take anything out.
That the PropTool doesn't optimise nor support conditional compilation is one of the things we are stuck with ( at least for now ). If one needs to develop an object which is both for the OBEX and needs to be compact for your own project with methods removed there's possibly no choice but to maintain two separate versions of that object, or a single 'bloated version' which can be trimmed down by a pre-processing utility such as CLEAN.