Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Toggle main menu visibility
Loading...
Searching...
No Matches
limited_pool.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2023 Roc Streaming authors
3
*
4
* This Source Code Form is subject to the terms of the Mozilla Public
5
* License, v. 2.0. If a copy of the MPL was not distributed with this
6
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
*/
8
9
//! @file roc_core/limited_pool.h
10
//! @brief Limited Pool.
11
12
#ifndef ROC_CORE_LIMITED_POOL_H_
13
#define ROC_CORE_LIMITED_POOL_H_
14
15
#include "
roc_core/ipool.h
"
16
#include "
roc_core/memory_limiter.h
"
17
#include "
roc_core/noncopyable.h
"
18
19
namespace
roc
{
20
namespace
core
{
21
22
//! Decorator around IPool to make it memory limited.
23
class
LimitedPool
:
public
NonCopyable<LimitedPool>,
public
IPool
{
24
public
:
25
//! Initialize.
26
LimitedPool
(
IPool
& pool,
MemoryLimiter
& memory_limiter);
27
28
//! Get size of the allocation per object.
29
virtual
size_t
allocation_size
()
const
;
30
31
//! Get size of the object.
32
virtual
size_t
object_size
()
const
;
33
34
//! Reserve memory for given number of objects.
35
//! @returns
36
//! false if allocation failed.
37
virtual
ROC_ATTR_NODISCARD
bool
reserve
(
size_t
n_objects);
38
39
//! Allocate memory for an object, after checking with the memory limiter.
40
//! @returns
41
//! pointer to a maximum aligned uninitialized memory for a new object
42
//! or NULL if memory can't be allocated.
43
virtual
void
*
allocate
();
44
45
//! Return memory to pool, then update the memory limiter.
46
virtual
void
deallocate
(
void
* memory);
47
48
private
:
49
IPool
& pool_;
50
MemoryLimiter
& memory_limiter_;
51
};
52
53
}
// namespace core
54
}
// namespace roc
55
56
#endif
// ROC_CORE_LIMITED_POOL_H_
ROC_ATTR_NODISCARD
#define ROC_ATTR_NODISCARD
Emit warning if function result is not checked.
Definition
attributes.h:31
roc::core::IPool
Memory pool interface.
Definition
ipool.h:23
roc::core::LimitedPool::deallocate
virtual void deallocate(void *memory)
Return memory to pool, then update the memory limiter.
roc::core::LimitedPool::allocate
virtual void * allocate()
Allocate memory for an object, after checking with the memory limiter.
roc::core::LimitedPool::LimitedPool
LimitedPool(IPool &pool, MemoryLimiter &memory_limiter)
Initialize.
roc::core::LimitedPool::reserve
virtual ROC_ATTR_NODISCARD bool reserve(size_t n_objects)
Reserve memory for given number of objects.
roc::core::LimitedPool::object_size
virtual size_t object_size() const
Get size of the object.
roc::core::LimitedPool::allocation_size
virtual size_t allocation_size() const
Get size of the allocation per object.
roc::core::MemoryLimiter
Memory limiter. This class can be used to keep track of memory being consumed. This is done through t...
Definition
memory_limiter.h:27
ipool.h
Memory pool interface.
memory_limiter.h
Memory limiter.
roc::core
General-purpose building blocks and platform abstraction layer.
roc
Root namespace.
noncopyable.h
Non-copyable object.
roc_core
limited_pool.h
Generated by
1.17.0