Differences between a simulator and a real machine
Source: Internet
Author: User
The simulator is to port the Symbian OS kernel to the Win32 platform. In most cases, the simulator environment is similar to the real machine, but there are still the following differences, some of which are enough to bring a lot of trouble to developers. Byte alignment and memory restrictions will be highlighted.
1. Guide Program
On a real machine, run a boot program to initialize a series of hardware before starting the kernel. The simulator directly starts the internal kernel (run epoc.exe)
2. File System Support
3. Floating Point Type
Symbian OS supports floating point type through treal32 (C ++ float type) and treal64 (C ++ double type). The simulator is based on Intel x86 processor, so it supports this floating point type in hardware. The hardware of the real machine is not necessarily supported. When a program uses a large number of floating-point functions, you need to pay attention to the huge performance gap caused by the lack of hardware support for the real machine.
4. Machine byte alignment
To reduce costs and energy consumption, arm uses a 32-bit RISC architecture. Therefore, 32-bit variables must be aligned according to the 32-bit machine byte boundary. In other words, the address must be a multiple of 4. For example,
Tint * P; // pointer to Integers
...
Tint I = * P; // get from a pointer
This section Code It works normally only when the IP address of P is a multiple of 4. Otherwise, an access conflict error is reported.
In general, this restriction is transparent to programmers Because struct and class members are automatically completed by the compiler. When you encounter the following code, you must pay attention to the limitations of byte alignment.
Ttext8 array [200];
For (tint I = 0; I <= 196; I ++)
{
Tint * P = (tint *) array [I]; // needs a cast
Tint n = * P; // four bytes from the array makes one integer?
}
This kind of code works fine in the simulator and can be compiled on the real machine. However, an access conflict occurs when the number of loops reaches 2nd, because the address of P is 1 greater than that of 4.
To avoid such problems, you can write as follows:
Ttext8 array [200];
For (tint I = 0; I <196; I ++)
{
Tany * P = array [I]; // really a Tany *, so no cast needed!
Tint N;
Mem: Copy (& N, P, sizeof (Tint); // copy byte by byte
}
5. Memory limit
The total heap capacity of the simulator is 64 MB by default. This value can be set using the megabytesoffreemory keyword. You can use the epocheapsize keyword of the MMP file to set the initial and maximum size of the default heap of the program,
The default stack size of a program on a real machine is only 8 KB, And the stack size on the simulator can be increased to the upper limit of windows. It may be okay because the program abused the stack space on the simulator, but the stack overflow Kern-exec 3 error will be reported on the real machine. Use the epocstacksize keyword in MMP to set the stack size used by the Program (this keyword is not supported by the simulator)
6. Process Simulation
7. Timetable
8. Serial Port
9. Timer
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.