[fpc-pascal] What is the best memory optimization parameter

Jeppe Johansen jeppe at j-software.dk
Wed Jun 15 22:37:08 CEST 2016

On 06/15/2016 06:04 PM, czd wrote:
> Hi all,
> What is the extreme memory optimization parameter to compile fpc for the
> embedded system? And could someone tell me what is the minimum memory
> specification for freepascal to run?
> Thanks.
Depends on your platform really but usually the short answer is: all of 
them :)

On the most extreme end of the scale there has been a proof of concept 
RTL built for an AVR ATTiny28 which does not have any RAM at all, except 
for 8 levels of hardware call stack. FPC could compile for that with 
some careful hacking.

But usually on an embedded ARM core you would usually see an idle memory 
usage of around 32-80 bytes of RAM for the RTL depending on how advanced 
features you need. Heap manager requires a lot more of course, 
initialization tables a little bit, soft fpu also a tiny bit, etc.

On ARM Cortex-M cores I usually compile with -O4 -Oonostackframe -XX. 
That's pretty much all that is needed. Disabling the nostackframe 
optimization is required for those specific cpu types due to a yet to be 
fixed bug.

The only important trick is to always end your main program routine with 
a "while true do;". This (usually) cuts out the finalization code saving 
quite a bit of RAM and Flash.
And of course do not use exceptions or ansistrings/managed types in general.

Best Regards,

More information about the fpc-pascal mailing list