CopperSpice API
1.9.2
|
Discussion about implicit sharing or copy on write. More...
Classes | |
class | QBitArray |
Stores an array of bits More... | |
class | QBitmap |
Monochrome (1-bit depth) pixmaps More... | |
class | QBrush |
Defines the fill pattern of shapes drawn by QPainter More... | |
class | QByteArray |
Stores a sequence of bytes More... | |
class | QCache< Key, T > |
Used to store elements in a cache container More... | |
class | QContiguousCache< T > |
Container providing a contiguous cache More... | |
class | QCursor |
Mouse cursor with an arbitrary shape More... | |
class | QDir |
Information about a given directory More... | |
class | QFileInfo |
Information about a given file More... | |
class | QFont |
Specifies a font used for drawing text More... | |
class | QFontInfo |
General information about fonts More... | |
class | QFontMetrics |
Font metrics information More... | |
class | QFontMetricsF |
Provides font metrics information More... | |
class | QGLColormap |
Used for installing custom colormaps into a QGLWidget More... | |
class | QGradient |
QGradient class is used in combination with QBrush to specify gradient fills More... | |
class | QIcon |
Scalable icons in different modes and states More... | |
class | QImage |
Represents a bit map image More... | |
class | QKeySequence |
Encapsulates a key sequence as used by shortcuts More... | |
class | QLocale |
Formats data based on a given language or country More... | |
class | QPainterPath |
Container for painting operations, enabling graphical shapes to be constructed and reused More... | |
class | QPalette |
Contains color groups for each widget state More... | |
class | QPen |
Defines how a QPainter should draw lines and outlines of shapes More... | |
class | QPicture |
Paint device that records and replays QPainter commands More... | |
class | QPixmap |
Off-screen image representation which can be used as a paint device More... | |
class | QPolygon |
Vector of points using integer precision More... | |
class | QPolygonF |
Vector of points using floating point precision More... | |
class | QRegion |
Clip region for a painter More... | |
class | QSqlField |
Manipulates the fields in SQL database tables and views More... | |
class | QSqlQuery |
Means of executing and manipulating SQL statements More... | |
class | QSqlRecord |
Encapsulates a database record More... | |
class | QTextBoundaryFinder |
Provides a way of finding Unicode text boundaries in a string More... | |
class | QTextCursor |
Offers an API to access and modify QTextDocuments More... | |
class | QTextDocumentFragment |
Piece of formatted text from a QTextDocument More... | |
class | QTextFormat |
Formatting information for a QTextDocument More... | |
There are several classes in CopperSpice which still use "implicit data sharing" which in C++ is more commonly referred to as "copy on write". This was done to minimize copying and was implemented before C++ had move semantics. Implicitly shared classes were more efficient before the addition of move semantics in C++. The basic idea is to defer a copy of the data as long as possible.
Refer to references for a detailed description of rvalues and move semantics.
An implicitly shared class consists of a pointer to a shared area of memory, which contains a reference count and the actual data. When an implicitly shared object is created the reference count is 1. The reference count is incremented when a new object references the shared data and decremented when the object no longer references the shared data. The shared data is deleted when the reference count becomes zero.
Implicit sharing allows a program to reduce memory usage when the same data is referenced by many instances. If you want to implement an implicitly shared class, use the QSharedData and QSharedDataPointer classes. For information on how implicit sharing works with threads, refer to Threads and Implicitly Shared Classes.
The classes listed above are implicitly shared. In this example p1
and p2
share data until QPainter::begin() is called for p2
, because painting a pixmap will modify it.