QtBase  v6.3.1
outofline.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2021 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtTest module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21 ** included in the packaging of this file. Please review the following
22 ** information to ensure the GNU General Public License requirements will
23 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24 **
25 ** $QT_END_LICENSE$
26 **
27 ****************************************************************************/
28 
29 #include <QList>
30 #include "qrawvector.h"
31 #include <vector>
32 
33 // Used as accumulator in tests:
34 double accumulate = 0;
35 
37 {
39  for (int i = 0; i != million; ++i)
40  v[i] = i;
41  return v;
42 }
43 
45 {
47  for (int i = 0; i != million; ++i)
48  v[i] = i;
49  return v.mutateToVector();
50 }
51 
53 {
54  std::vector<double> v(million);
55  for (int i = 0; i != million; ++i)
56  v[i] = i;
57  return QVector<double>(v.begin(), v.end());
58 }
59 
60 
61 std::vector<double> stdvector_fill_and_return_helper()
62 {
63  std::vector<double> v(million);
64  for (int i = 0; i != million; ++i)
65  v[i] = i;
66  return v;
67 }
68 
70 
71 static inline int alignmentThreshold()
72 {
73  // malloc on 32-bit platforms should return pointers that are 8-byte aligned or more
74  // while on 64-bit platforms they should be 16-byte aligned or more
75  return 2 * sizeof(void*);
76 }
77 
79 {
80  return static_cast<QVectorData *>(alignment > alignmentThreshold() ? qMallocAligned(size, alignment) : ::malloc(size));
81 }
82 
84 
86 {
87  if (alignment > alignmentThreshold())
88  return static_cast<QVectorData *>(qReallocAligned(x, newsize, oldsize, alignment));
89  return static_cast<QVectorData *>(realloc(x, newsize));
90 }
91 
93 {
94  if (alignment > alignmentThreshold())
95  qFreeAligned(x);
96  else
97  ::free(x);
98 }
99 
100 int QVectorData::grow(int sizeOfHeader, int size, int sizeOfT)
101 {
102  return qCalculateGrowingBlockSize(size, sizeOfT, sizeOfHeader).elementCount;
103 }
104 
small capitals from c petite p scientific i
[1]
Definition: afcover.h:80
Definition: qlist.h:108
uint alignment
CalculateGrowingBlockSizeResult qCalculateGrowingBlockSize(qsizetype elementCount, qsizetype elementSize, qsizetype headerSize) noexcept
Definition: qarraydata.cpp:121
QT_BEGIN_NAMESPACE void * qMallocAligned(size_t size, size_t alignment)
Definition: qmalloc.cpp:52
void * qReallocAligned(void *oldptr, size_t newsize, size_t oldsize, size_t alignment)
Definition: qmalloc.cpp:57
void qFreeAligned(void *ptr)
Definition: qmalloc.cpp:106
GLsizei const GLfloat * v
[13]
GLint GLint GLint GLint GLint x
[0]
GLenum GLuint GLintptr GLsizeiptr size
[1]
const int million
Definition: qrawvector.h:44
#define Q_REFCOUNT_INITIALIZE_STATIC
Definition: qrefcount.h:88
std::vector< double > stdvector_fill_and_return_helper()
Definition: outofline.cpp:61
double accumulate
Definition: outofline.cpp:34
QVector< double > mixedvector_fill_and_return_helper()
Definition: outofline.cpp:52
QVector< double > qvector_fill_and_return_helper()
Definition: outofline.cpp:36
QVector< double > qrawvector_fill_and_return_helper()
Definition: outofline.cpp:44
static void free(QVectorData *data, int alignment)
Definition: outofline.cpp:92
static QVectorData * allocate(int size, int alignment)
Definition: outofline.cpp:78
static const QVectorData shared_null
Definition: qrawvector.h:66
static int grow(int sizeOfHeader, int size, int sizeOfT)
Definition: outofline.cpp:100
static QVectorData * reallocate(QVectorData *old, int newsize, int oldsize, int alignment)
Definition: outofline.cpp:85