03.01.2013 Views

Chapter 1

Chapter 1

Chapter 1

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

ARM data alignment rules are strict; x86 alignment rules are more relaxed. If you need<br />

alignment, copy potentially unaligned data byte by byte into an aligned area. For example,<br />

TBuf8 buffer;<br />

TInt index = 39; // not a multiple of 4!!<br />

TInt* p = (TInt*)(buffer.Ptr() + index);<br />

TInt i = *p;<br />

The cast ought to be a warning of trouble; this code is platform dependent. It happens to<br />

work on x86, but not on ARM, where it generates an alignment fault. You need to use code<br />

like:<br />

TBuf8 buffer;<br />

TInt index = 39; // not a multiple of 4!!<br />

TInt i;<br />

Mem::Copy(&i, buffer.Ptr() + index, 4);<br />

On a target phone, each application and server is a separate process, with its own .exe. On<br />

the emulator, there is only one process, so applications use apprun.dll instead of<br />

apprun.exe and most servers are delivered as DLLs. There are established patterns for<br />

working around these issues; they affect very few lines of Symbian OS code. For<br />

applications, the issue is addressed for you, so you don't need to worry. If you write a server,<br />

you'll need to copy one of the standard patterns, such as the one in <strong>Chapter</strong> 19.<br />

On the emulator, all Symbian OS threads run in the same PC address space. Standard<br />

Symbian OS programming uses active objects and the client-server architecture, which<br />

means that deliberate use of shared memory is very rare. So very few programs are by<br />

nature difficult to debug because of differences between the emulator and target machines.<br />

Some very obscure and awkward bugs can result, however, whereby code with random<br />

reads or writes appears to work under the emulator, but crashes quickly on a target<br />

machine.<br />

The emulator builds on top of Win32 APIs; real Symbian OS builds on a microkernel,<br />

hardware, and device drivers. If you're programming these, then the emulator won't help;<br />

you need the real hardware. Likewise, the emulator is of less help if you're working with<br />

communications in which there are always device-specific issues. Timing resolution is<br />

different on the real hardware and on a PC. This makes a big difference when implementing<br />

anything that is timer-driven, particularly any communications software. On the real<br />

hardware, the timing resolution is finer (typically 1/64 s compared with 1/10 s on the PC), so<br />

fast timers can be very slow on the PC. This makes it especially important to test<br />

communications software on the real hardware as early as possible.<br />

On target phones, Symbian OS controls the executable image format and has incorporated<br />

UIDs into it. On the emulator, Symbian OS clearly doesn't control the executable image<br />

format, so we use the stub.uid.cpp file to generate UIDs into the .E32_UID data<br />

segment. Files on the emulator are recognized as such by the application architecture, but<br />

aren't checked by the Windows loader as they are on a target machine.<br />

For some projects, you can build for the emulator only, until the day before you ship. A<br />

simple rebuild, and you're up and running on the target hardware and everything's fine. But it<br />

would be unwise to think all projects are like that, even all those that 'ought to be'. Any of the<br />

issues I mentioned above could be a factor in your project. The best way to tackle issues is<br />

to see them a long way in advance. Build periodically for the real hardware. Check for<br />

obvious bugs, UI considerations, and performance. Take action early on, while you can still<br />

make a difference.

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

Saved successfully!

Ooh no, something went wrong!