Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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"
18
19namespace roc {
20namespace core {
21
22//! Decorator around IPool to make it memory limited.
23class LimitedPool : public NonCopyable<LimitedPool>, public IPool {
24public:
25 //! Initialize.
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
48private:
49 IPool& pool_;
50 MemoryLimiter& memory_limiter_;
51};
52
53} // namespace core
54} // namespace roc
55
56#endif // ROC_CORE_LIMITED_POOL_H_
#define ROC_ATTR_NODISCARD
Emit warning if function result is not checked.
Definition attributes.h:31
Memory pool interface.
Definition ipool.h:23
Decorator around IPool to make it memory limited.
virtual bool reserve(size_t n_objects)
Reserve memory for given number of objects.
virtual void deallocate(void *memory)
Return memory to pool, then update the memory limiter.
virtual void * allocate()
Allocate memory for an object, after checking with the memory limiter.
LimitedPool(IPool &pool, MemoryLimiter &memory_limiter)
Initialize.
virtual size_t object_size() const
Get size of the object.
virtual size_t allocation_size() const
Get size of the allocation per object.
Memory limiter. This class can be used to keep track of memory being consumed. This is done through t...
Base class for non-copyable objects.
Definition noncopyable.h:23
Shared ownership intrusive pointer.
Definition shared_ptr.h:32
Memory pool interface.
Memory limiter.
Root namespace.
Non-copyable object.