Reducing code size of Symbian C++ apps

From Nokia Developer Wiki
Jump to: navigation, search

This article contains tips for reducing the code size of Symbian C++ applications.

Article Metadata
Created: vasant21 (26 May 2007)
Last edited: hamishwillee (27 Jan 2012)


Avoid excessive TRAP harnesses

TRAP harnesses use up space when they are compiled. Code that contains many TRAP macros will consume a lot of space, and may well be incorrectly designed (TRAP harness are intended to allow advanced development of special error handling and recovery routines. As a rule of thumb, if your class has more than 5 TRAPs you are almost certainly doing something wrong.

Avoid debug code in release builds

Code for logging, debugging, or testing should be excluded from release builds unless absolutely necessary. The compiler directive #ifdef _DEBUG can be used for this purpose.

Avoid Unnecessary Exported Functions

When functions are exported using IMPORT_C and EXPORT_C from a DLL, they use up space for the "export table". Only functions that need to be used outside of the DLL should be exported.

Avoid unnecessary virtual functions

Unnecessary virtual functions should be avoided for similar to exports, as they create extra vtable functions.

Decomposable functions

Where a number of functions perform similar tasks it may be possible to abstract these out into a single function which is parameterized to perform the different tasks required. A common example of this kind of thing is a class that implements both NewL() and NewLC(). Rather than duplicate the code in both functions, NewL() can just call NewLC(), performing a CleanupStack::Pop() afterwards.

Use common controls

If possible, use framework controls that are available in the system (or other shared DLLs) instead of developing new ones.

This page was last modified on 27 January 2012, at 09:15.
54 page views in the last 30 days.