• Home
  • Textbooks
  • Programming Mobile Devices: An Introduction for Practitioners
  • Memory Management

Programming Mobile Devices: An Introduction for Practitioners

Tommi Mikkonen

Chapter 2

Memory Management - all with Video Answers

Educators


Chapter Questions

Problem 1

What kind of data structure would be adequate for a calendar in a mobile device? How would adding of new items or deleting those that already exist be implemented? Could closing the application and opening it again change the data structure? What would such a dynamic data structure enable? How about the structure that is stored in the disk, assuming that the used physical implementation consists of flash memory?

Check back soon!

Problem 2

How would you implement a data structure similar to the Symbian OS cleanup stack, but which would allow removal of items from the data structure based on name, reference, or some other identifier? How does your implementation correspond to the Symbian OS solution in terms of complexity and performance? Could the data structure be used for garbage collection as well?

Check back soon!

Problem 3

What problems can you find in the following excerpt of a Symbian program? How and in what situations would they degenerate the program's execution? How should the program be corrected?
// Operations to be identified in the screen.
enum TMode \{EEat, ESleep, EWait\};
// Temporary resource for drawing.
class CMyResource
\{
public:
CMyResource (CScreenShot \& aParent);
ConstructL ();
-CMyResource ();
void ShowEatingItemL();
void ShowSleepingItemL ();
void ShowlaitingItemL();
private:
...
\};
// Draw the right symbol to myWindow.
void Behave(TMode aMode, CScreenShot\& myWindow)
\{
CMyResource *res $=0 ; / /$ Local drawing resource
// Local two-phase construction.
res = new CMyResource (myWindow);
res->ConstructL ();
CleanupStack: : PushL (res);
// Selecting symbol to draw.
switch (aMode)
\{
case EEat:
res->ShowEatingItemL ();
break;
case ESleep:
res->ShowSleepingItemL ();
break;
case EWait:
res->ShowWaitingItemL ();
break;
default:
User: : Leave (KNoSuchActivity) ;
break;
\} // switch
// Drawing complete, resource no longer needed.
CleanupStack: : PopAndDestroy(); // res
delete res;
// Fix figure to the screen.
MakeImagePermanentL (myWindow) ;
\}

Check back soon!

Problem 4

Compose a procedure that calls itself recursively, and passes an object containing an array of 25 integers (each integer is 4 bytes, so the size is at least 100 bytes) as a parameter. How many rounds can the program execute in the Symbian OS environment? Are there differences in the emulator and an actual Symbian device? What if the program is modified to reserve memory from the heap in a similar fashion? Does the allocation from stack or from heap affect performance?

Check back soon!

Problem 5

What kind of design choices could be made to ensure that there are always enough resources for making an emergency call? Is reserving memory enough, or should there be also other means?

Check back soon!

Problem 6

In what kinds of situations would it make sense to offer only NewL or NewLC, but not both, in the interface of a Symbian OS class? What are the fundamental differences in the use of these two methods?

Check back soon!

Problem 7

What would be a realistic assumption for a third-party programmer on the amount of memory that will be made available for her program, assuming that only application-specific issues, not including any infrastructure requirements, are considered? How does the use of graphics, sounds, etc. affect the requirements of the application?

Check back soon!