Qt Embedded performance optimization

Source: Internet
Author: User

Qt EmbeddedAndQtIn the same way, three authorization protocols GPL, LGPL, and Commercial are provided after version 4.5. For a long timeQt EmbeddedIn development,Qt EmbeddedPerformance is not very concerned, and with confidence in qtsoftware, did not carefully understand how to optimizeQt Embedded. I participated in a national embedded competition some time ago and usedQt Embedded4. 5.0 on the s3c2410 platform, there was actually a phenomenon of a card. For embedded development, resources are extremely important,QtAs the resources of equipment become larger and more scarce, optimization becomes extremely important. InQt EmbeddedThis document contains an introduction to performance optimization. I have made a simple translation and hope it can be used in the embedded field.Qt EmbeddedDevelopers are helpful.

Qt Performance Optimization

When developing embedded applications on devices with scarce resources,QtFor Windows CE andQtForEmbeddedLinux requires memory and CPU by adjusting a series of parameters to enable or disable them. These selection parameter methods are mainly used in programming style, connection mode, and memory allocation.

Note that the most direct way to save resources is to remove unnecessary features during compilation. For details, see the fine tuning features section in the document.

1. programming style

2. Static link vs Dynamic Link

3. Replace the Memory Allocation Method

4. bypass the backup storage Zone

Programming style

Instead of selecting to create dialogs and controls at any time when they are needed and deleting them when they are no longer needed, it is better to create them at one time and use QWidget: hide () as needed () and QWidget: show () function. To avoid slow application startup, you should postpone the creation of the dialog box and control until necessary. All this will improve the performance of the CPU, and only a little more memory is required, but this will speed up the running efficiency.

Dynamic Vs static Link

Many CPU and memory are linked to the process through the ELF (Executable and Linking Format), and significant savings can be achieved through the static Compilation Program; rather than in actual execution, collect and dynamically link parts related to the Qt library. All applications will be created into an independent execution file, which is statically linked to the Qt library.

These will improve the program startup time and reduce memory usage, but the premise will damage the flexible and practical features, once a new application is added, a separate execution file must be re-compiled) and program robustness if one application has bugs, it will harm other applications ).

Create a static Compilation

To compile Qt into a static library, use the-static parameter during compilation:

 
  1. ./configure –static 

In order to establish the application set as an integrated application, each application should be designed as a separate control or control set) and the minimum amount of code should be used in the main () function as much as possible. Then, designing an independent application can improve the interaction of other applications.QtExtended platform is a typical example: it can be created using a series of dynamic links or as a separate static independent application.

Note that the program will dynamically link the Standard C Library and other libraries because other applications may use them on the target platform.

This method is not always an option when installing the final client application, but when developing a separate application package for a device subject to CPU and memory restrictions, this option is very helpful.

Replace the Memory Allocation Method

On Some platforms, libraries compiled using C ++ have very poor performance in the use of "new" and "delete" operations. To improve the Memory Allocation performance in the future, you can use the following functions instead:

 
  1. void *operator new[](size_t size)  
  2.  {  
  3.      return malloc(size);  
  4.  }  
  5.  
  6.  void *operator new(size_t size)  
  7.  {  
  8.      return malloc(size);  
  9.  }  
  10.  
  11.  void operator delete[](void *ptr)  
  12.  {  
  13.      free(ptr);  
  14.  }  
  15.  
  16.  void operator delete[](void *ptr, size_t)  
  17.  {  
  18.      free(ptr);  
  19.  }  
  20.  
  21.  void operator delete(void *ptr)  
  22.  {  
  23.      free(ptr);  
  24.  }  
  25.  
  26.  void operator delete(void *ptr, size_t)  
  27.  {  
  28.      free(ptr);  
  29.  } 

The above instances show that the necessary code is allocated using C memory.

Bypass backup storage Zone

When running,QtThe backup storage zone is used. For example, a drawing cache can reduce flickering and support overlapping graphics operations.

In general, the default process is as follows. For each client, the control is imported into the memory, and the server is responsible for extracting the content from the memory and drawing it on the screen. However, some hardware is well known and there are already cases of embedded software. These are very helpful for bypassing the backup storage zone and can run the client to directly operate the hardware skillfully. There are two ways to achieve direct painting: the first method is to use each controlQt ::The WA_PaintOnScreen window attribute. The other is the area where the QDirectPainter class is used to save the frame cache. For more information, see the direct painting details in the architecture documentation.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.