Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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
<
memory_resource
>
9
10
#
include
<
tlsf
.
h
>
11
12
QT_BEGIN_NAMESPACE
13
14
namespace
QtMultimediaPrivate
{
15
16
QTlsfMemoryResource
::
QTlsfMemoryResource
(
std
::size_t preallocatedBytes, memory_resource *upstream):
17
m_allocationSize
{
18
preallocatedBytes
+ 8192,
// over-allocate by 8k for tlsf header
19
},
20
m_upstream
{
21
upstream
,
22
}
23
{
24
m_buffer =
reinterpret_cast
<std::byte *>(operator
new
(m_allocationSize, poolAlignment));
25
26
m_tlsf = QtPrivate::tlsf_create_with_pool(m_buffer, m_allocationSize);
27
Q_ASSERT(m_tlsf);
28
}
29
30
QTlsfMemoryResource
::~QTlsfMemoryResource()
31
{
32
QtPrivate::tlsf_destroy(m_tlsf);
33
::operator
delete
(m_buffer, poolAlignment);
34
}
35
36
void
*
QTlsfMemoryResource
::
do_allocate
(size_t bytes, size_t alignment)
37
{
38
void
*ret = QtPrivate::tlsf_memalign(m_tlsf, alignment, bytes);
39
if
(Q_UNLIKELY(ret ==
nullptr
))
40
ret = m_upstream->allocate(bytes, alignment);
41
42
return
ret;
43
}
44
45
void
QTlsfMemoryResource
::
do_deallocate
(
void
*p, size_t bytes, size_t alignment)
46
{
47
if
(Q_LIKELY(p >= m_buffer && p < m_buffer + m_allocationSize))
48
QtPrivate::tlsf_free(m_tlsf, p);
49
else
50
m_upstream->deallocate(p, bytes, alignment);
51
}
52
53
bool
QTlsfMemoryResource
::
do_is_equal
(
const
memory_resource &other)
const
noexcept
54
{
55
return
this
== &other;
56
}
57
58
}
// namespace QtMultimediaPrivate
59
60
QT_END_NAMESPACE
QtMultimediaPrivate
Definition
qaudiosystem_p.h:51
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
QtMultimediaPrivate::QTlsfMemoryResource::~QTlsfMemoryResource
~QTlsfMemoryResource() override
Definition
qmemory_resource_tlsf.cpp:30
QtMultimediaPrivate::QTlsfMemoryResource::do_deallocate
void do_deallocate(void *p, size_t bytes, size_t alignment) override
Definition
qmemory_resource_tlsf.cpp:45
QtMultimediaPrivate::QTlsfMemoryResource::do_allocate
void * do_allocate(size_t bytes, size_t alignment) override
Definition
qmemory_resource_tlsf.cpp:36
QtMultimediaPrivate::QTlsfMemoryResource::do_is_equal
bool do_is_equal(const memory_resource &other) const noexcept override
Definition
qmemory_resource_tlsf.cpp:53
QtMultimediaPrivate::QTlsfMemoryResource::QTlsfMemoryResource
QTlsfMemoryResource(std::size_t preallocatedBytes, pmr::memory_resource *upstream=pmr::get_default_resource())
Definition
qmemory_resource_tlsf.cpp:16
qtmultimedia
src
multimedia
audio
qmemory_resource_tlsf.cpp
Generated on
for Qt by
1.16.1