1 | // Copyright (C) 2021 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #ifndef QSSG_GLSLMEMORYPOOL_H |
5 | #define QSSG_GLSLMEMORYPOOL_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists purely as an |
12 | // implementation detail. This header file may change from version to |
13 | // version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include <QtQuick3DGlslParser/private/glsl_p.h> |
19 | |
20 | #include <cstddef> |
21 | #include <new> |
22 | |
23 | QT_BEGIN_NAMESPACE |
24 | |
25 | namespace GLSL { |
26 | |
27 | class MemoryPool; |
28 | |
29 | class Q_QUICK3DGLSLPARSER_EXPORT MemoryPool |
30 | { |
31 | MemoryPool(const MemoryPool &other); |
32 | void operator =(const MemoryPool &other); |
33 | |
34 | public: |
35 | MemoryPool(); |
36 | ~MemoryPool(); |
37 | |
38 | void reset(); |
39 | |
40 | inline void *allocate(size_t size) |
41 | { |
42 | size = (size + 7) & ~7; |
43 | if (_ptr && (_ptr + size < _end)) { |
44 | void *addr = _ptr; |
45 | _ptr += size; |
46 | return addr; |
47 | } |
48 | return allocate_helper(size); |
49 | } |
50 | |
51 | private: |
52 | void *allocate_helper(size_t size); |
53 | |
54 | private: |
55 | char **_blocks; |
56 | int _allocatedBlocks; |
57 | int _blockCount; |
58 | char *_ptr; |
59 | char *_end; |
60 | |
61 | enum |
62 | { |
63 | BLOCK_SIZE = 8 * 1024, |
64 | DEFAULT_BLOCK_COUNT = 8 |
65 | }; |
66 | }; |
67 | |
68 | class Q_QUICK3DGLSLPARSER_EXPORT Managed |
69 | { |
70 | Managed(const Managed &other); |
71 | void operator = (const Managed &other); |
72 | |
73 | public: |
74 | Managed(); |
75 | virtual ~Managed(); |
76 | |
77 | void *operator new(size_t size, MemoryPool *pool); |
78 | void operator delete(void *); |
79 | void operator delete(void *, MemoryPool *); |
80 | }; |
81 | |
82 | } // namespace GLSL |
83 | |
84 | QT_END_NAMESPACE |
85 | |
86 | #endif // QSSG_GLSLMEMORYPOOL_H |
87 | |