CopperSpice API  1.7.1
Implicit Sharing

Classes

class  QBitArray
 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
 QByteArray class provides an array of bytes More...
 
class  QCache< Key, T >
 Provides a cache More...
 
class  QContiguousCache< T >
 Class template providing a contiguous cache More...
 
class  QCursor
 Mouse cursor with an arbitrary shape More...
 
class  QDir
 Access to directory structures and their contents More...
 
class  QFileInfo
 System-independent file information 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
 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
 Converts between numbers and their string representations in various languages More...
 
class  QPainterPath
 Container for painting operations, enabling graphical shapes to be constructed and reused More...
 
class  QPalette
 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...
 

Detailed Description

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.

Refer to references for a detailed description of rvalues and 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.

Overview

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.

List of 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.

QPixmap p1, p2;
p1.load("image.bmp");
p2 = p1; // p1 and p2 share data
QPainter paint;
paint.begin(&p2); // detaches p2 from p1
paint.drawText(0,50, "Hi");
paint.end();
Warning
Do not copy an implicitly shared container while you are iterating over it using a non-const STL-style iterator.