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
qmemory_resource_tlsf.cpp
Go to the documentation of this file.
1
// Copyright (C) 2025 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4
#
include
"qmemory_resource_tlsf_p.h"
5
6
#
include
<
QtCore
/
qassert
.
h
>
7
8
#
include
<
tlsf
.
h
>
9
10
QT_BEGIN_NAMESPACE
11
12
namespace
QtMultimediaPrivate
{
13
14
QTlsfMemoryResource
::QTlsfMemoryResource(
std
::size_t preallocatedBytes, memory_resource *upstream):
15
m_allocationSize {
16
preallocatedBytes + 8192,
// over-allocate by 8k for tlsf header
17
},
18
m_upstream{
19
upstream,
20
}
21
{
22
m_buffer =
reinterpret_cast
<std::byte *>(operator
new
(m_allocationSize, poolAlignment));
23
24
m_tlsf = QtPrivate::tlsf_create_with_pool(m_buffer, m_allocationSize);
25
Q_ASSERT(m_tlsf);
26
}
27
28
QTlsfMemoryResource
::~QTlsfMemoryResource()
29
{
30
QtPrivate::tlsf_destroy(m_tlsf);
31
::operator
delete
(m_buffer, poolAlignment);
32
}
33
34
void
*
QTlsfMemoryResource
::
do_allocate
(size_t bytes, size_t alignment)
35
{
36
void
*ret = QtPrivate::tlsf_memalign(m_tlsf, alignment, bytes);
37
if
(Q_UNLIKELY(ret ==
nullptr
))
38
ret = m_upstream->allocate(bytes, alignment);
39
40
return
ret;
41
}
42
43
void
QTlsfMemoryResource
::
do_deallocate
(
void
*p, size_t bytes, size_t alignment)
44
{
45
if
(Q_LIKELY(p >= m_buffer && p < m_buffer + m_allocationSize))
46
QtPrivate::tlsf_free(m_tlsf, p);
47
else
48
m_upstream->deallocate(p, bytes, alignment);
49
}
50
51
bool
QTlsfMemoryResource
::
do_is_equal
(
const
memory_resource &other)
const
noexcept
52
{
53
return
this
== &other;
54
}
55
56
}
// namespace QtMultimediaPrivate
57
58
QT_END_NAMESPACE
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
QtMultimediaPrivate::impl
Definition
qaudiosystem_p.h:257
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
QtMultimediaPrivate::QTlsfMemoryResource::do_deallocate
void do_deallocate(void *p, size_t bytes, size_t alignment) override
Definition
qmemory_resource_tlsf.cpp:43
QtMultimediaPrivate::QTlsfMemoryResource::do_allocate
void * do_allocate(size_t bytes, size_t alignment) override
Definition
qmemory_resource_tlsf.cpp:34
QtMultimediaPrivate::QTlsfMemoryResource::do_is_equal
bool do_is_equal(const memory_resource &other) const noexcept override
Definition
qmemory_resource_tlsf.cpp:51
QtMultimediaPrivate::QTlsfMemoryResource::QTlsfMemoryResource
Q_MULTIMEDIA_EXPORT QTlsfMemoryResource(std::size_t preallocatedBytes, pmr::memory_resource *upstream=pmr::get_default_resource())
Definition
qmemory_resource_tlsf.cpp:14
qtmultimedia
src
multimedia
audio
qmemory_resource_tlsf.cpp
Generated on
for Qt by
1.18.0