Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
glslmemorypool.cpp
Go to the documentation of this file.
1
// Copyright (C) 2021 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
6
#
include
"glslmemorypool_p.h"
7
#
include
<
cstring
>
8
#
include
<
cassert
>
9
#
include
<
cstdlib
>
10
11
QT_BEGIN_NAMESPACE
12
13
using
namespace
GLSL;
14
15
MemoryPool::MemoryPool()
16
: _blocks(
nullptr
),
17
_allocatedBlocks(0),
18
_blockCount(-1),
19
_ptr(
nullptr
),
20
_end(
nullptr
)
21
{ }
22
23
MemoryPool::~MemoryPool()
24
{
25
if
(_blocks) {
26
for
(
int
i = 0; i < _allocatedBlocks; ++i) {
27
if
(
char
*b = _blocks[i])
28
std::free(b);
29
}
30
31
std::free(_blocks);
32
}
33
}
34
35
void
MemoryPool::reset()
36
{
37
_blockCount = -1;
38
_ptr = _end =
nullptr
;
39
}
40
41
void
*MemoryPool::allocate_helper(size_t size)
42
{
43
assert
(size < BLOCK_SIZE);
44
45
if
(++_blockCount == _allocatedBlocks) {
46
if
(! _allocatedBlocks)
47
_allocatedBlocks = DEFAULT_BLOCK_COUNT;
48
else
49
_allocatedBlocks *= 2;
50
51
_blocks = (
char
**) realloc(_blocks,
sizeof
(
char
*) * _allocatedBlocks);
52
53
for
(
int
index = _blockCount; index < _allocatedBlocks; ++index)
54
_blocks[index] =
nullptr
;
55
}
56
57
char
*&block = _blocks[_blockCount];
58
59
if
(! block)
60
block = (
char
*) std::malloc(BLOCK_SIZE);
61
62
_ptr = block;
63
_end = _ptr + BLOCK_SIZE;
64
65
void
*addr = _ptr;
66
_ptr += size;
67
return
addr;
68
}
69
70
Managed::Managed()
71
{ }
72
73
Managed::~Managed()
74
{ }
75
76
void
*Managed::operator
new
(size_t size, MemoryPool *pool)
77
{
return
pool->allocate(size); }
78
79
void
Managed::operator
delete
(
void
*)
80
{ }
81
82
void
Managed::operator
delete
(
void
*, MemoryPool *)
83
{ }
84
85
QT_END_NAMESPACE
assert
#define assert
Definition
qcborcommon_p.h:29
qtquick3d
src
glslparser
glslmemorypool.cpp
Generated on
for Qt by
1.18.0