Add files from qtdoc for documentation modularization.
Change-Id: I6ea5c139e632460c516116a302f27f5c902f5561 Reviewed-by: Jerome Pasion <jerome.pasion@nokia.com>
138
doc/src/core/implicit-sharing.qdoc
Normal file
@ -0,0 +1,138 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the documentation of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:FDL$
|
||||
** GNU Free Documentation License
|
||||
** Alternatively, this file may be used under the terms of the GNU Free
|
||||
** Documentation License version 1.3 as published by the Free Software
|
||||
** Foundation and appearing in the file included in the packaging of
|
||||
** this file.
|
||||
**
|
||||
** Other Usage
|
||||
** Alternatively, this file may be used in accordance with the terms
|
||||
** and conditions contained in a signed written agreement between you
|
||||
** and Nokia.
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
/* TODO: Move some of the documentation from QSharedDataPointer into this
|
||||
document. */
|
||||
|
||||
/*!
|
||||
\group shared
|
||||
\title Implicitly Shared Classes
|
||||
*/
|
||||
|
||||
/*!
|
||||
\page implicit-sharing.html
|
||||
\title Implicit Sharing
|
||||
\ingroup qt-basic-concepts
|
||||
|
||||
\brief Reference counting for fast copying.
|
||||
|
||||
\keyword implicit data sharing
|
||||
\keyword implicit sharing
|
||||
\keyword implicitly shared
|
||||
\keyword reference counting
|
||||
\keyword shared implicitly
|
||||
\keyword shared classes
|
||||
|
||||
Many C++ classes in Qt use implicit data sharing to maximize
|
||||
resource usage and minimize copying. Implicitly shared classes are
|
||||
both safe and efficient when passed as arguments, because only a
|
||||
pointer to the data is passed around, and the data is copied only
|
||||
if and when a function writes to it, i.e., \e {copy-on-write}.
|
||||
|
||||
\tableofcontents
|
||||
|
||||
\section1 Overview
|
||||
|
||||
A shared class consists of a pointer to a shared data block that
|
||||
contains a reference count and the data.
|
||||
|
||||
When a shared object is created, it sets the reference count to 1. The
|
||||
reference count is incremented whenever a new object references the
|
||||
shared data, and decremented when the object dereferences the shared
|
||||
data. The shared data is deleted when the reference count becomes
|
||||
zero.
|
||||
|
||||
\keyword deep copy
|
||||
\keyword shallow copy
|
||||
|
||||
When dealing with shared objects, there are two ways of copying an
|
||||
object. We usually speak about \e deep and \e shallow copies. A deep
|
||||
copy implies duplicating an object. A shallow copy is a reference
|
||||
copy, i.e. just a pointer to a shared data block. Making a deep copy
|
||||
can be expensive in terms of memory and CPU. Making a shallow copy is
|
||||
very fast, because it only involves setting a pointer and incrementing
|
||||
the reference count.
|
||||
|
||||
Object assignment (with operator=()) for implicitly shared objects is
|
||||
implemented using shallow copies.
|
||||
|
||||
The benefit of sharing is that a program does not need to duplicate
|
||||
data unnecessarily, which results in lower memory use and less copying
|
||||
of data. Objects can easily be assigned, sent as function arguments,
|
||||
and returned from functions.
|
||||
|
||||
Implicit sharing takes place behind the scenes; the programmer
|
||||
does not need to worry about it. Even in multithreaded
|
||||
applications, implicit sharing takes place, as explained in
|
||||
\l{Thread-Support in Qt Modules#Threads and Implicitly Shared Classes}
|
||||
{Threads and Implicitly Shared Classes}.
|
||||
|
||||
When implementing your own implicitly shared classes, use the
|
||||
QSharedData and QSharedDataPointer classes.
|
||||
|
||||
\section1 Implicit Sharing in Detail
|
||||
|
||||
Implicit sharing automatically detaches the object from a shared
|
||||
block if the object is about to change and the reference count is
|
||||
greater than one. (This is often called \e {copy-on-write} or
|
||||
\e {value semantics}.)
|
||||
|
||||
An implicitly shared class has total control of its internal data. In
|
||||
any member functions that modify its data, it automatically detaches
|
||||
before modifying the data.
|
||||
|
||||
The QPen class, which uses implicit sharing, detaches from the shared
|
||||
data in all member functions that change the internal data.
|
||||
|
||||
Code fragment:
|
||||
\snippet doc/src/snippets/code/doc_src_groups.cpp 0
|
||||
|
||||
|
||||
\section1 List of Classes
|
||||
|
||||
The classes listed below automatically detach from common data if
|
||||
an object is about to be changed. The programmer will not even
|
||||
notice that the objects are shared. Thus you should treat
|
||||
separate instances of them as separate objects. They will always
|
||||
behave as separate objects but with the added benefit of sharing
|
||||
data whenever possible. For this reason, you can pass instances
|
||||
of these classes as arguments to functions by value without
|
||||
concern for the copying overhead.
|
||||
|
||||
Example:
|
||||
\snippet doc/src/snippets/code/doc_src_groups.cpp 1
|
||||
|
||||
In this example, \c p1 and \c p2 share data until QPainter::begin()
|
||||
is called for \c p2, because painting a pixmap will modify it.
|
||||
|
||||
\warning Do not copy an implicitly shared container (QMap,
|
||||
QVector, etc.) while you are iterating over it using an non-const
|
||||
\l{STL-style iterator}.
|
||||
|
||||
\keyword implicitly shared classes
|
||||
\annotatedlist shared
|
||||
*/
|
BIN
doc/src/images/abstract-connections.png
Normal file
After Width: | Height: | Size: 19 KiB |
BIN
doc/src/images/alphafill.png
Normal file
After Width: | Height: | Size: 156 B |
BIN
doc/src/images/bearings.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
doc/src/images/brush-outline.png
Normal file
After Width: | Height: | Size: 452 B |
BIN
doc/src/images/coordinatesystem-analogclock.png
Normal file
After Width: | Height: | Size: 9.5 KiB |
BIN
doc/src/images/coordinatesystem-line-antialias.png
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
doc/src/images/coordinatesystem-line-raster.png
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
doc/src/images/coordinatesystem-line.png
Normal file
After Width: | Height: | Size: 26 KiB |
BIN
doc/src/images/coordinatesystem-rect-antialias.png
Normal file
After Width: | Height: | Size: 19 KiB |
BIN
doc/src/images/coordinatesystem-rect-raster.png
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
doc/src/images/coordinatesystem-rect.png
Normal file
After Width: | Height: | Size: 32 KiB |
BIN
doc/src/images/cursor-arrow.png
Normal file
After Width: | Height: | Size: 171 B |
BIN
doc/src/images/cursor-busy.png
Normal file
After Width: | Height: | Size: 201 B |
BIN
doc/src/images/cursor-closedhand.png
Normal file
After Width: | Height: | Size: 147 B |
BIN
doc/src/images/cursor-cross.png
Normal file
After Width: | Height: | Size: 130 B |
BIN
doc/src/images/cursor-forbidden.png
Normal file
After Width: | Height: | Size: 199 B |
BIN
doc/src/images/cursor-hand.png
Normal file
After Width: | Height: | Size: 159 B |
BIN
doc/src/images/cursor-hsplit.png
Normal file
After Width: | Height: | Size: 155 B |
BIN
doc/src/images/cursor-ibeam.png
Normal file
After Width: | Height: | Size: 124 B |
BIN
doc/src/images/cursor-openhand.png
Normal file
After Width: | Height: | Size: 160 B |
BIN
doc/src/images/cursor-sizeall.png
Normal file
After Width: | Height: | Size: 174 B |
BIN
doc/src/images/cursor-sizeb.png
Normal file
After Width: | Height: | Size: 161 B |
BIN
doc/src/images/cursor-sizef.png
Normal file
After Width: | Height: | Size: 161 B |
BIN
doc/src/images/cursor-sizeh.png
Normal file
After Width: | Height: | Size: 145 B |
BIN
doc/src/images/cursor-sizev.png
Normal file
After Width: | Height: | Size: 141 B |
BIN
doc/src/images/cursor-uparrow.png
Normal file
After Width: | Height: | Size: 132 B |
BIN
doc/src/images/cursor-vsplit.png
Normal file
After Width: | Height: | Size: 161 B |
BIN
doc/src/images/cursor-wait.png
Normal file
After Width: | Height: | Size: 172 B |
BIN
doc/src/images/cursor-whatsthis.png
Normal file
After Width: | Height: | Size: 191 B |
BIN
doc/src/images/javaiterators1.png
Normal file
After Width: | Height: | Size: 1.0 KiB |
BIN
doc/src/images/javaiterators2.png
Normal file
After Width: | Height: | Size: 2.0 KiB |
BIN
doc/src/images/modelview-begin-append-columns.png
Normal file
After Width: | Height: | Size: 12 KiB |
BIN
doc/src/images/modelview-begin-append-rows.png
Normal file
After Width: | Height: | Size: 8.8 KiB |
BIN
doc/src/images/modelview-begin-insert-columns.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
doc/src/images/modelview-begin-insert-rows.png
Normal file
After Width: | Height: | Size: 12 KiB |
BIN
doc/src/images/modelview-begin-remove-columns.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
doc/src/images/modelview-begin-remove-rows.png
Normal file
After Width: | Height: | Size: 11 KiB |
BIN
doc/src/images/modelview-move-rows-1.png
Normal file
After Width: | Height: | Size: 19 KiB |
BIN
doc/src/images/modelview-move-rows-2.png
Normal file
After Width: | Height: | Size: 19 KiB |
BIN
doc/src/images/modelview-move-rows-3.png
Normal file
After Width: | Height: | Size: 9.1 KiB |
BIN
doc/src/images/modelview-move-rows-4.png
Normal file
After Width: | Height: | Size: 9.2 KiB |
BIN
doc/src/images/paintsystem-icon.png
Normal file
After Width: | Height: | Size: 5.3 KiB |
BIN
doc/src/images/palette.png
Normal file
After Width: | Height: | Size: 65 KiB |
BIN
doc/src/images/qcolor-cmyk.png
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
doc/src/images/qcolor-hsv.png
Normal file
After Width: | Height: | Size: 21 KiB |
BIN
doc/src/images/qcolor-hue.png
Normal file
After Width: | Height: | Size: 26 KiB |
BIN
doc/src/images/qcolor-rgb.png
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
doc/src/images/qcolor-saturation.png
Normal file
After Width: | Height: | Size: 2.1 KiB |
BIN
doc/src/images/qcolor-value.png
Normal file
After Width: | Height: | Size: 1.2 KiB |
BIN
doc/src/images/qeasingcurve-inback.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
doc/src/images/qeasingcurve-inbounce.png
Normal file
After Width: | Height: | Size: 3.1 KiB |
BIN
doc/src/images/qeasingcurve-incirc.png
Normal file
After Width: | Height: | Size: 2.5 KiB |
BIN
doc/src/images/qeasingcurve-incubic.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
doc/src/images/qeasingcurve-inelastic.png
Normal file
After Width: | Height: | Size: 3.2 KiB |
BIN
doc/src/images/qeasingcurve-inexpo.png
Normal file
After Width: | Height: | Size: 2.6 KiB |
BIN
doc/src/images/qeasingcurve-inoutback.png
Normal file
After Width: | Height: | Size: 3.2 KiB |
BIN
doc/src/images/qeasingcurve-inoutbounce.png
Normal file
After Width: | Height: | Size: 3.3 KiB |
BIN
doc/src/images/qeasingcurve-inoutcirc.png
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
doc/src/images/qeasingcurve-inoutcubic.png
Normal file
After Width: | Height: | Size: 2.9 KiB |
BIN
doc/src/images/qeasingcurve-inoutelastic.png
Normal file
After Width: | Height: | Size: 3.4 KiB |
BIN
doc/src/images/qeasingcurve-inoutexpo.png
Normal file
After Width: | Height: | Size: 2.9 KiB |
BIN
doc/src/images/qeasingcurve-inoutquad.png
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
doc/src/images/qeasingcurve-inoutquart.png
Normal file
After Width: | Height: | Size: 2.9 KiB |
BIN
doc/src/images/qeasingcurve-inoutquint.png
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
doc/src/images/qeasingcurve-inoutsine.png
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
doc/src/images/qeasingcurve-inquad.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
doc/src/images/qeasingcurve-inquart.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
doc/src/images/qeasingcurve-inquint.png
Normal file
After Width: | Height: | Size: 2.6 KiB |
BIN
doc/src/images/qeasingcurve-insine.png
Normal file
After Width: | Height: | Size: 2.5 KiB |
BIN
doc/src/images/qeasingcurve-linear.png
Normal file
After Width: | Height: | Size: 2.3 KiB |
BIN
doc/src/images/qeasingcurve-outback.png
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
doc/src/images/qeasingcurve-outbounce.png
Normal file
After Width: | Height: | Size: 3.3 KiB |
BIN
doc/src/images/qeasingcurve-outcirc.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
doc/src/images/qeasingcurve-outcubic.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
doc/src/images/qeasingcurve-outelastic.png
Normal file
After Width: | Height: | Size: 3.3 KiB |
BIN
doc/src/images/qeasingcurve-outexpo.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
doc/src/images/qeasingcurve-outinback.png
Normal file
After Width: | Height: | Size: 3.0 KiB |
BIN
doc/src/images/qeasingcurve-outinbounce.png
Normal file
After Width: | Height: | Size: 3.5 KiB |
BIN
doc/src/images/qeasingcurve-outincirc.png
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
doc/src/images/qeasingcurve-outincubic.png
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
doc/src/images/qeasingcurve-outinelastic.png
Normal file
After Width: | Height: | Size: 3.8 KiB |
BIN
doc/src/images/qeasingcurve-outinexpo.png
Normal file
After Width: | Height: | Size: 2.9 KiB |
BIN
doc/src/images/qeasingcurve-outinquad.png
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
doc/src/images/qeasingcurve-outinquart.png
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
doc/src/images/qeasingcurve-outinquint.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
doc/src/images/qeasingcurve-outinsine.png
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
doc/src/images/qeasingcurve-outquad.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
doc/src/images/qeasingcurve-outquart.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
doc/src/images/qeasingcurve-outquint.png
Normal file
After Width: | Height: | Size: 2.6 KiB |
BIN
doc/src/images/qeasingcurve-outsine.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
doc/src/images/qgradient-conical.png
Normal file
After Width: | Height: | Size: 3.9 KiB |
BIN
doc/src/images/qgradient-linear.png
Normal file
After Width: | Height: | Size: 714 B |
BIN
doc/src/images/qgradient-radial.png
Normal file
After Width: | Height: | Size: 2.3 KiB |
BIN
doc/src/images/qimage-32bit_scaled.png
Normal file
After Width: | Height: | Size: 24 KiB |
BIN
doc/src/images/qimage-8bit_scaled.png
Normal file
After Width: | Height: | Size: 24 KiB |
BIN
doc/src/images/qline-coordinates.png
Normal file
After Width: | Height: | Size: 9.2 KiB |
BIN
doc/src/images/qline-point.png
Normal file
After Width: | Height: | Size: 8.3 KiB |
BIN
doc/src/images/qlineargradient-pad.png
Normal file
After Width: | Height: | Size: 2.2 KiB |
BIN
doc/src/images/qlineargradient-reflect.png
Normal file
After Width: | Height: | Size: 2.7 KiB |