The Android mobile phone operating system has been well received by many users, especially programmers. Because of its open-source nature, it can well meet various user needs. Here we will analyze some concepts related to Android floating point to help you better understand this operating system.
- Android lifecycle concepts
- Overview of Android Defects
- Android glossary Overview
- Introduction to the correct implementation of Android read/write files
- Android full screen
Avoid using Android floating point numbers
Before the emergence of the Pentium CPU, the game designers did the most integer operations. With the arrival of the Pentium, the floating point computing processor has become a built-in feature of the CPU. The use of floating point and integer can make your game run more smoothly. Generally on a desktop computer, you can use floating point operations at will.
Unfortunately, the embedded processor usually does not support Android floating point operations. All the operations on "float" and "double" are implemented through software. Some basic floating point operations can be completed in milliseconds.
It is even an integer. Some chips have hardware support for multiplication but lack Division support. In this case, the division and modulo operations of integers are also completed by software. Therefore, be cautious when using hash tables or performing a large number of mathematical operations.
Performance data
To illustrate our point of view, we listed a table to indicate the time required for some basic operations. These time values are not absolute values, but a mixture of CPU time and clock time. As the system improves, the running time will be shortened. However, we need to pay attention to the ratio between these values. For example, adding a member variable will take four times more time than adding a local variable.
- Action Time
- Add a local variable 1
- Add a member variable 4
- Call String.length() 5
- Call empty static native method 5
- Call empty static method 12
- Call empty virtual method 12.5
- Call empty interface method 15
- Call Iterator:next() on a HashMap 165
- Call put() on a HashMap 600
- Inflate 1 View from XML 22,000
- Inflate 1 LinearLayout containing 1 TextView 25,000
- Inflate 1 LinearLayout containing 6 View objects 100,000
- Inflate 1 LinearLayout containing 6 TextView objects 135,000
- Launch an empty activity 3,000,000
To write elegant and efficient code for an embedded system, you need to understand exactly what your code is to do. If you really want to allocate an iterator, use foreach for the List. It is your choice, not an unintentional one.
The concepts of Android floating point are introduced here. If there is backup, there is no problem. Know what you want to do. Focus on your greatest enthusiasm, understand your code clearly, and try your best to make it run faster.