Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qarraydata.cpp File Reference
#include <QtCore/qarraydata.h>
#include <QtCore/private/qnumeric_p.h>
#include <QtCore/private/qtools_p.h>
#include <QtCore/qmath.h>
#include <QtCore/qbytearray.h>
#include <QtCore/qstring.h>
#include <stdlib.h>
+ Include dependency graph for qarraydata.cpp:

Go to the source code of this file.

Functions

QT_BEGIN_NAMESPACE qsizetype qCalculateBlockSize (qsizetype elementCount, qsizetype elementSize, qsizetype headerSize) noexcept
 
CalculateGrowingBlockSizeResult qCalculateGrowingBlockSize (qsizetype elementCount, qsizetype elementSize, qsizetype headerSize) noexcept
 
static qsizetype reserveExtraBytes (qsizetype allocSize)
 
static qsizetype calculateBlockSize (qsizetype &capacity, qsizetype objectSize, qsizetype headerSize, QArrayData::AllocationOption option)
 
static QArrayDataallocateData (qsizetype allocSize)
 

Function Documentation

◆ allocateData()

static QArrayData * allocateData ( qsizetype  allocSize)
static

Definition at line 140 of file qarraydata.cpp.

References header().

Referenced by QContiguousCache< T >::QContiguousCache(), QArrayData::allocate(), QContiguousCache< T >::clear(), and QContiguousCache< T >::setCapacity().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ calculateBlockSize()

static qsizetype calculateBlockSize ( qsizetype capacity,
qsizetype  objectSize,
qsizetype  headerSize,
QArrayData::AllocationOption  option 
)
inlinestatic

Definition at line 126 of file qarraydata.cpp.

References capacity, QArrayData::Grow, headerSize, qCalculateBlockSize(), and qCalculateGrowingBlockSize().

Referenced by QArrayData::allocate(), and QArrayData::reallocateUnaligned().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ qCalculateBlockSize()

QT_BEGIN_NAMESPACE qsizetype qCalculateBlockSize ( qsizetype  elementCount,
qsizetype  elementSize,
qsizetype  headerSize 
)
noexcept
Since
5.7

Returns the memory block size for a container containing elementCount elements, each of elementSize bytes, plus a header of headerSize bytes. That is, this function returns {elementCount * elementSize + headerSize}

but unlike the simple calculation, it checks for overflows during the multiplication and the addition.

Both elementCount and headerSize can be zero, but elementSize cannot.

This function returns -1 on overflow or if the memory block size would not fit a qsizetype.

Definition at line 52 of file qarraydata.cpp.

References headerSize, Q_ASSERT, Q_UNLIKELY, qAddOverflow(), and qMulOverflow().

Referenced by calculateBlockSize(), and qCalculateGrowingBlockSize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ qCalculateGrowingBlockSize()

CalculateGrowingBlockSizeResult qCalculateGrowingBlockSize ( qsizetype  elementCount,
qsizetype  elementSize,
qsizetype  headerSize 
)
noexcept
Since
5.7

Returns the memory block size and the number of elements that will fit in that block for a container containing elementCount elements, each of elementSize bytes, plus a header of headerSize bytes. This function assumes the container will grow and pre-allocates a growth factor.

Both elementCount and headerSize can be zero, but elementSize cannot.

This function returns -1 on overflow or if the memory block size would not fit a qsizetype.

Note
The memory block may contain up to elementSize - 1 bytes more than needed.

Definition at line 85 of file qarraydata.cpp.

References headerSize, Q_UNLIKELY, qCalculateBlockSize(), and qNextPowerOfTwo().

Referenced by calculateBlockSize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ reserveExtraBytes()

static qsizetype reserveExtraBytes ( qsizetype  allocSize)
inlinestatic

Returns allocSize plus extra reserved bytes necessary to store '\0'.

Definition at line 115 of file qarraydata.cpp.

References Q_UNLIKELY, qAddOverflow(), and qMax().

Referenced by QArrayData::allocate(), and QArrayData::reallocateUnaligned().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: