Sophie

Sophie

distrib > Mageia > 7 > x86_64 > by-pkgid > 1dd17e0d683ef79b4bb6872bbf359d7f > files > 6641

qt4-doc-4.8.7-26.2.mga7.noarch.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en_US" lang="en_US">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- emb-performance.qdoc -->
  <title>Qt 4.8: Qt Performance Tuning</title>
  <link rel="stylesheet" type="text/css" href="style/style.css" />
  <script src="scripts/jquery.js" type="text/javascript"></script>
  <script src="scripts/functions.js" type="text/javascript"></script>
  <link rel="stylesheet" type="text/css" href="style/superfish.css" />
  <link rel="stylesheet" type="text/css" href="style/narrow.css" />
  <!--[if IE]>
<meta name="MSSmartTagsPreventParsing" content="true">
<meta http-equiv="imagetoolbar" content="no">
<![endif]-->
<!--[if lt IE 7]>
<link rel="stylesheet" type="text/css" href="style/style_ie6.css">
<![endif]-->
<!--[if IE 7]>
<link rel="stylesheet" type="text/css" href="style/style_ie7.css">
<![endif]-->
<!--[if IE 8]>
<link rel="stylesheet" type="text/css" href="style/style_ie8.css">
<![endif]-->

<script src="scripts/superfish.js" type="text/javascript"></script>
<script src="scripts/narrow.js" type="text/javascript"></script>

</head>
<body class="" onload="CheckEmptyAndLoadList();">
 <div class="header" id="qtdocheader">
    <div class="content"> 
    <div id="nav-logo">
      <a href="index.html">Home</a></div>
    <a href="index.html" class="qtref"><span>Qt Reference Documentation</span></a>
    <div id="narrowsearch"></div>
    <div id="nav-topright">
      <ul>
        <li class="nav-topright-home"><a href="http://qt.digia.com/">Qt HOME</a></li>
        <li class="nav-topright-dev"><a href="http://qt-project.org/">DEV</a></li>
        <li class="nav-topright-doc nav-topright-doc-active"><a href="http://qt-project.org/doc/">
          DOC</a></li>
        <li class="nav-topright-blog"><a href="http://blog.qt.digia.com/">BLOG</a></li>
      </ul>
    </div>
    <div id="shortCut">
      <ul>
        <li class="shortCut-topleft-inactive"><span><a href="index.html">Qt 4.8</a></span></li>
        <li class="shortCut-topleft-active"><a href="http://qt-project.org/doc/">ALL VERSIONS        </a></li>
      </ul>
     </div>
 <ul class="sf-menu" id="narrowmenu"> 
             <li><a href="#">API Lookup</a> 
                 <ul> 
                     <li><a href="classes.html">Class index</a></li> 
           <li><a href="functions.html">Function index</a></li> 
           <li><a href="modules.html">Modules</a></li> 
           <li><a href="namespaces.html">Namespaces</a></li> 
           <li><a href="qtglobal.html">Global Declarations</a></li> 
           <li><a href="qdeclarativeelements.html">QML elements</a></li> 
             </ul> 
             </li> 
             <li><a href="#">Qt Topics</a> 
                 <ul> 
                        <li><a href="qt-basic-concepts.html">Programming with Qt</a></li>  
                        <li><a href="qtquick.html">Device UIs &amp; Qt Quick</a></li>  
                        <li><a href="qt-gui-concepts.html">UI Design with Qt</a></li>  
                        <li><a href="supported-platforms.html">Supported Platforms</a></li>  
                        <li><a href="technology-apis.html">Qt and Key Technologies</a></li>  
                        <li><a href="best-practices.html">How-To's and Best Practices</a></li>  
              </ul> 
                 </li> 
                 <li><a href="#">Examples</a> 
                     <ul> 
                       <li><a href="all-examples.html">Examples</a></li> 
                       <li><a href="tutorials.html">Tutorials</a></li> 
                       <li><a href="demos.html">Demos</a></li> 
                       <li><a href="qdeclarativeexamples.html">QML Examples</a></li> 
                </ul> 
                     </li> 
                 </ul> 
    </div>
  </div>
  <div class="wrapper">
    <div class="hd">
      <span></span>
    </div>
    <div class="bd group">
      <div class="sidebar">
        <div class="searchlabel">
          Search index:</div>
        <div class="search" id="sidebarsearch">
          <form id="qtdocsearch" action="" onsubmit="return false;">
            <fieldset>
              <input type="text" name="searchstring" id="pageType" value="" />
 <div id="resultdialog"> 
 <a href="#" id="resultclose">Close</a> 
 <p id="resultlinks" class="all"><a href="#" id="showallresults">All</a> | <a href="#" id="showapiresults">API</a> | <a href="#" id="showarticleresults">Articles</a> | <a href="#" id="showexampleresults">Examples</a></p> 
 <p id="searchcount" class="all"><span id="resultcount"></span><span id="apicount"></span><span id="articlecount"></span><span id="examplecount"></span>&nbsp;results:</p> 
 <ul id="resultlist" class="all"> 
 </ul> 
 </div> 
            </fieldset>
          </form>
        </div>
        <div class="box first bottombar" id="lookup">
          <h2 title="API Lookup"><span></span>
            API Lookup</h2>
          <div  id="list001" class="list">
          <ul id="ul001" >
              <li class="defaultLink"><a href="classes.html">Class index</a></li>
              <li class="defaultLink"><a href="functions.html">Function index</a></li>
              <li class="defaultLink"><a href="modules.html">Modules</a></li>
              <li class="defaultLink"><a href="namespaces.html">Namespaces</a></li>
              <li class="defaultLink"><a href="qtglobal.html">Global Declarations</a></li>
              <li class="defaultLink"><a href="qdeclarativeelements.html">QML elements</a></li>
            </ul> 
          </div>
        </div>
        <div class="box bottombar" id="topics">
          <h2 title="Qt Topics"><span></span>
            Qt Topics</h2>
          <div id="list002" class="list">
            <ul id="ul002" >
               <li class="defaultLink"><a href="qt-basic-concepts.html">Programming with Qt</a></li> 
               <li class="defaultLink"><a href="qtquick.html">Device UIs &amp; Qt Quick</a></li> 
               <li class="defaultLink"><a href="qt-gui-concepts.html">UI Design with Qt</a></li> 
               <li class="defaultLink"><a href="supported-platforms.html">Supported Platforms</a></li>  
               <li class="defaultLink"><a href="technology-apis.html">Qt and Key Technologies</a></li> 
               <li class="defaultLink"><a href="best-practices.html">How-To's and Best Practices</a></li> 
            </ul>  
          </div>
        </div>
        <div class="box" id="examples">
          <h2 title="Examples"><span></span>
            Examples</h2>
          <div id="list003" class="list">
        <ul id="ul003">
              <li class="defaultLink"><a href="all-examples.html">Examples</a></li>
              <li class="defaultLink"><a href="tutorials.html">Tutorials</a></li>
              <li class="defaultLink"><a href="demos.html">Demos</a></li>
              <li class="defaultLink"><a href="qdeclarativeexamples.html">QML Examples</a></li>
            </ul> 
          </div>
        </div>
      </div>
      <div class="wrap">
        <div class="toolbar">
          <div class="breadcrumb toolblock">
            <ul>
              <li class="first"><a href="index.html">Home</a></li>
              <!--  Breadcrumbs go here -->
<li>Qt Performance Tuning</li>
            </ul>
          </div>
          <div class="toolbuttons toolblock">
            <ul>
              <li id="smallA" class="t_button">A</li>
              <li id="medA" class="t_button active">A</li>
              <li id="bigA" class="t_button">A</li>
              <li id="print" class="t_button"><a href="javascript:this.print();">
                <span>Print</span></a></li>
            </ul>
        </div>
        </div>
        <div class="content mainContent">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#programming-style">Programming Style</a></li>
<li class="level1"><a href="#static-vs-dynamic-linking">Static vs. Dynamic Linking</a></li>
<li class="level1"><a href="#alternative-memory-allocation">Alternative Memory Allocation</a></li>
<li class="level1"><a href="#bypassing-the-backing-store">Bypassing the Backing Store</a></li>
</ul>
</div>
<h1 class="title">Qt Performance Tuning</h1>
<span class="subtitle"></span>
<!-- $$$qt-performance.html-description -->
<div class="descr"> <a name="details"></a>
<p>When building embedded applications on low-powered devices, <a href="qtce.html">Qt for Windows CE</a> and <a href="qt-embedded-linux.html">Qt for Embedded Linux</a> provide a number of options that reduce the memory and/or CPU requirements by making various trade-offs. These options range from variations in programming style, to linking and memory allocation.</p>
<p>Note that the most direct way of saving resources, is to avoid compiling in features that are not required. See the <a href="fine-tuning-features.html">fine tuning features</a> documentation for details.</p>
<a name="programming-style"></a>
<h2>Programming Style</h2>
<p>Rather than creating dialogs and widgets every time they are needed, and delete them when they are no longer required, create them once and use the <a href="qwidget.html#hide">QWidget::hide</a>() and <a href="qwidget.html#show">QWidget::show</a>() functions whenever appropriate. To avoid a slow startup of the application, delay the creation of dialogs and widgets until they are requested. All this will improve the CPU performance, it requires a little more memory, but will be much faster.</p>
<a name="static-vs-dynamic-linking"></a>
<h2>Static vs. Dynamic Linking</h2>
<p>A lot of CPU and memory is used by the ELF (Executable and Linking Format) linking process. Significant savings can be achieved by using a static build of the application suite; rather than having a collection of executables which link dynamically to Qt's libraries, all the applications is built into into a single executable which is statically linked to Qt's libraries.</p>
<p>This improves the start-up time and reduces memory usage at the expense of flexibility (to add a new application, you must recompile the single executable) and robustness (if one application has a bug, it might harm other applications).</p>
<table class="generic" width="100%">
 <tr valign="top" class="odd"><td ><b>Creating a Static Build</b><p>To compile Qt as a static library, use the <tt>-static</tt> option when running configure:</p>
<pre class="cpp"> ./configure -static</pre>
<p>To build the application suite as an all-in-one application, design each application as a stand-alone widget (or set of widgets) with only minimal code in the <tt>main()</tt> function. Then, write an application that provides a means of switching between the applications. The <a href="qt.html">Qt</a> Extended platform is an example using this approach: It can be built either as a set of dynamically linked executables, or as a single static application.</p>
<p>Note that the application still should link dynamically against the standard C library and any other libraries which might be used by other applications on the target device.</p>
</td></tr>
</table>
<p>When installing end-user applications, this approach may not be an option, but when building a single application suite for a device with limited CPU power and memory, this option could be very beneficial.</p>
<a name="alternative-memory-allocation"></a>
<h2>Alternative Memory Allocation</h2>
<p>The libraries shipped with some C++ compilers on some platforms have poor performance in the built-in &quot;new&quot; and &quot;delete&quot; operators. Improved memory allocation and performance may be gained by re-implementing these functions:</p>
<pre class="cpp"> <span class="type">void</span> <span class="operator">*</span><span class="keyword">operator</span> <span class="keyword">new</span><span class="operator">[</span><span class="operator">]</span>(size_t size)
 {
     <span class="keyword">return</span> malloc(size);
 }

 <span class="type">void</span> <span class="operator">*</span><span class="keyword">operator</span> <span class="keyword">new</span>(size_t size)
 {
     <span class="keyword">return</span> malloc(size);
 }

 <span class="type">void</span> <span class="keyword">operator</span> <span class="keyword">delete</span><span class="operator">[</span><span class="operator">]</span>(<span class="type">void</span> <span class="operator">*</span>ptr)
 {
     free(ptr);
 }

 <span class="type">void</span> <span class="keyword">operator</span> <span class="keyword">delete</span><span class="operator">[</span><span class="operator">]</span>(<span class="type">void</span> <span class="operator">*</span>ptr<span class="operator">,</span> size_t)
 {
     free(ptr);
 }

 <span class="type">void</span> <span class="keyword">operator</span> <span class="keyword">delete</span>(<span class="type">void</span> <span class="operator">*</span>ptr)
 {
     free(ptr);
 }

 <span class="type">void</span> <span class="keyword">operator</span> <span class="keyword">delete</span>(<span class="type">void</span> <span class="operator">*</span>ptr<span class="operator">,</span> size_t)
 {
     free(ptr);
 }</pre>
<p>The example above shows the necessary code to switch to the plain C memory allocators.</p>
<a name="bypassing-the-backing-store"></a>
<h2>Bypassing the Backing Store</h2>
<p>When rendering, Qt uses the concept of a backing store; i.e&#x2e;, a paint buffer, to reduce flicker and to support graphics operations such as blending.</p>
<p>The default behavior is for each client to render its widgets into memory while the server is responsible for putting the contents of the memory onto the screen. But when the hardware is known and well defined, as is often the case with software for embedded devices, it might be useful to bypass the backing store, allowing the clients to manipulate the underlying hardware directly. There are two approaches to direct painting: The first approach is to set the <a href="qt.html#WidgetAttribute-enum">Qt::WA_PaintOnScreen</a> window attribute for each widget, the other is to use the <a href="qdirectpainter.html">QDirectPainter</a> class to reserve a region of the framebuffer. For more information, see the <a href="qt-embedded-architecture.html#direct-painting">direct painting</a> section of the <a href="qt-embedded-architecture.html">architecture</a> documentation.</p>
</div>
<!-- @@@qt-performance.html -->
      </div>
    </div>
    </div> 
    <div class="ft">
      <span></span>
    </div>
  </div> 
  <div class="footer">
    <p>
      <acronym title="Copyright">&copy;</acronym> 2015 The Qt Company Ltd.
      Documentation contributions included herein are the copyrights of
      their respective owners.</p>
    <br />
    <p>
      The documentation provided herein is licensed under the terms of the
      <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation
      License version 1.3</a> as published by the Free Software Foundation.</p>
    <p>
      Documentation sources may be obtained from <a href="http://www.qt-project.org">
      www.qt-project.org</a>.</p>
    <br />
    <p>
      Qt and respective logos are trademarks of The Qt Company Ltd 
      in Finland and/or other countries worldwide. All other trademarks are property
      of their respective owners. <a title="Privacy Policy"
      href="http://en.gitorious.org/privacy_policy/">Privacy Policy</a></p>
  </div>

  <script src="scripts/functions.js" type="text/javascript"></script>
</body>
</html>