Ten C++ coding tips

This micro guide is the first of a colection dedicated to c++ dvelopers that want to prodcuce a more robust code.
These suggestions are only a quick guide based on our experience as mobile developers.

1) Ensure that your application responds to system shutdown events.

2) Ensure that your application responds to incoming system events. Remember that your application is operating on a multitasking enviromnment and for this reason you need to pay attention to focus gained/lost events to ensure that the software responds correctly when the user receives a high priority notification (i.e. an incoming call).

3) Your application has to handle with care the memory in order to avoid crashes and runtime errors. In order to avoid errors is mandatory to test the application not only on the emulator but test it frequently also in the target devices.

4) When it’s possible allocate objects on the heap rather than on the stack.

5) Close gracefully the application when system resources are unavailable especially when you encounter Ram issues.

6) Always remember to set member HBufC variables to null after deleting them if your purpose is to re-allocate to the same variables.

7) Remember that function whit a trailing “C” on their name automatically put the object on the CleanupStack and that if you put manually these objects on the stack they will be present twice.

8) Remembr always thea Symbian OS constructor must never Leave. If a C++ construcor Leaves there is no way to cleanup the partially cosntructed object because there is no pointere to it.

9) When passing or returnig an object to a function ensure that if you take ownership of the object you delete it! Symbian uses the convetion that pointers in a method indicates transfer of owbershio to the caller while references indicate that the ownership of the passed object remains with the origina owner.

10) Take care when implementing framework classes in your application. You should always derive from the platform specific framework



Leave a Reply

Your email address will not be published.