03.01.2013 Views

Chapter 1

Chapter 1

Chapter 1

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

You have to face some key issues here – issues that don't trouble modern desktop software<br />

developers:<br />

� You have to program efficiently so that your programs don't use RAM unnecessarily.<br />

We've already begun to see how descriptors help with that.<br />

� You have to release resources as soon as possible because you can't afford a running<br />

program to gobble up more and more RAM without ever releasing it.<br />

� You have to cope with out-of-memory errors. In fact, you have to cope with potential<br />

out of memory in every single operation that can allocate memory because an out-ofmemory<br />

condition can arise in any such operation.<br />

� When an out-of-memory situation arises that stops some operation from happening,<br />

you must not lose any user data, but must roll back to an acceptable and consistent<br />

state.<br />

� When an out-of-memory situation occurs partway through an operation that involves<br />

the allocation of several resources, you must clean up all those resources as part of the<br />

process of rolling back.<br />

Important These considerations are fundamental to a successful handheld<br />

system. An operating system for mobile phones that doesn't<br />

provide the programmer with good support in these areas is<br />

doomed.<br />

Here are some examples of where you might run out of memory when using a real mobile<br />

phone.<br />

When you launch a new application, resources are created first by the kernel (memory to<br />

hold information about the new process and thread used by the application), then by the<br />

application itself (the memory it requires), and then by various servers throughout the<br />

system. (The file server is constantly at the ready to load application resources, and the<br />

window server displays the application's graphics on-screen, and queues keyboard and<br />

pointer events to the application when it has focus.) At any time during this sequence, the<br />

attempt to allocate one of these resources may fail because of an out-of-memory condition.<br />

The whole application launch has to be called off, and the application, the kernel, and any<br />

servers that allocated resources during the aborted launch must then release them.<br />

Application launch requires a lot of resources, so it's a good guess that the whole operation<br />

might fail if the system is running out of them. However, each of the resources required by<br />

the application is allocated individually, and potential failure must be detected in each<br />

possible case. Proper cleanup must occur wherever the failure occurred.<br />

It's easy enough to clean up on application launch – you just kill everything and the<br />

application isn't launched. Nobody's data gets lost and the user understands what has<br />

happened.<br />

Other examples are more demanding. Imagine that you're typing into a word processor<br />

document. Each key you press potentially expands the buffers used to store and format the<br />

rich text object that's at the heart of the word processor application. If you press a key that<br />

requires the buffers to expand, but there is insufficient memory available, the operation will<br />

fail. In this case, it would clearly be quite wrong for the application to terminate – all your<br />

typing would be lost. Instead, the document must roll back to the state it was in before the<br />

key was processed, and any memory that was allocated successfully during the partially<br />

performed operation must be freed.<br />

In fact, the Symbian OS error handling and cleanup framework is good for more than OOM<br />

errors. Many operations can fail because of other environment conditions – reading and<br />

writing to files, opening files, sending and receiving over communications sessions. The<br />

error handling and cleanup framework can make it easier to deal with those kinds of errors<br />

too.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!