Mobiiliohjelmointi/Mobile programming

 

Exercise 2 – Memory management

 

This exercise focuses on how to handle memory, especially, how to allocate objects using the Two phase construction idiom. It also shows how to use T -type struct classes.

Resources

Download this application memConsole (zip file) that is used as a basis for the exercise.

Import the project.. Put the project zip into same drive as your symbian environment (usually c:, you can not use any directory under desktop, because "documents and settings" has spaces), unzip and press import from carbide.  Select Symbian OS-> Symbian bld.inf. Click next. Browse for bld.inf -file of your project. Next. Symbian OS SDK, select right SDK. Next. Select mmp-files, this time there is only file memconsole.mmp. Next. Project  name and the root directory should be ok. Press Finish. 

The project has 2-3 classes. These are CRecordStore, TScore and memconsole.  TScore stores two values, the name of a person and a numerical mark. CRecordStore saves these TScore records in an array. Memconsole is responsible for

1.        Initializing the TScore values,

2.        Creating the CRecordstore,

3.        Adding the TScore objects to CRecordStore.

:

Students Task :

  1. Complete the declaration of the CRecordStore class. CRecordsStore is a complicated type, with both C and T -type data attributes. As such, it needs the Two phased allocation discussed in the lectures. RecordStore.h file contains TODO-comments that point out the additions needed in the CRecordStore class.
  2. Implement new methods just added to the declaration of CRecordStore. Again, TODO comments instruct you in your task.
  3. Try to build the application. There should be no errors in this phase.
  4. Now it is time to start using the classes. This happens in  DoExample function (memconsole.cpp), where you will create CRecordStore and TScore objects and use them.  Again, follow the TODO instructions in the code to finish the exercise. Remember that T -type objects are allocated on the stack, as usual variables are, and CBase based objects are always allocated from the heap, using either new (ELeave) or NewL/C factory methods of a class.
  5. When you have finished TODO tasks. Build your application for the emulator. Run it. If your application does not show in the emulator you can run the created memconsole.exe file directly from the C:\Symbian\9.2\S60_3rd_FP1\Epoc32\release\winscw\udeb directory.