Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
limited_arena.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_arena.h
10//! @brief Limited Arena.
11
12#ifndef ROC_CORE_LIMITED_ARENA_H_
13#define ROC_CORE_LIMITED_ARENA_H_
14
15#include "roc_core/iarena.h"
18
19namespace roc {
20namespace core {
21
22//! Decorator around IArena to make it memory limited.
23class LimitedArena : public NonCopyable<>, public IArena {
24public:
25 //! Initialize.
27
28 //! Allocate memory after checking with the memory limiter.
29 //! @returns
30 //! pointer to a maximum aligned uninitialized memory at least of @p size
31 //! bytes or NULL if memory can't be allocated.
32 virtual void* allocate(size_t size);
33
34 //! Deallocate previously allocated memory.
35 virtual void deallocate(void* ptr);
36
37 //! Computes how many bytes will be actually allocated if allocate() is called with
38 //! given size. Covers all internal overhead, if any.
39 virtual size_t compute_allocated_size(size_t size) const;
40
41 //! Returns how many bytes was allocated for given pointer returned by allocate().
42 //! Covers all internal overhead, if any.
43 //! Returns same value as computed by compute_allocated_size(size).
44 virtual size_t allocated_size(void* ptr) const;
45
46private:
47 IArena& arena_;
48 MemoryLimiter& memory_limiter_;
49};
50
51} // namespace core
52} // namespace roc
53
54#endif // ROC_CORE_LIMITED_ARENA_H_
Memory arena interface.
Definition iarena.h:23
Decorator around IArena to make it memory limited.
virtual void * allocate(size_t size)
Allocate memory after checking with the memory limiter.
virtual void deallocate(void *ptr)
Deallocate previously allocated memory.
virtual size_t compute_allocated_size(size_t size) const
Computes how many bytes will be actually allocated if allocate() is called with given size....
LimitedArena(IArena &arena, MemoryLimiter &memory_limiter)
Initialize.
virtual size_t allocated_size(void *ptr) const
Returns how many bytes was allocated for given pointer returned by allocate(). Covers all internal ov...
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 arena interface.
Memory limiter.
Root namespace.
Non-copyable object.