Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Toggle main menu visibility
Loading...
Searching...
No Matches
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
"
16
#include "
roc_core/memory_limiter.h
"
17
#include "
roc_core/noncopyable.h
"
18
19
namespace
roc
{
20
namespace
core
{
21
22
//! Decorator around IArena to make it memory limited.
23
class
LimitedArena
:
public
NonCopyable<>,
public
IArena
{
24
public
:
25
//! Initialize.
26
LimitedArena
(
IArena
& arena,
MemoryLimiter
& memory_limiter);
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
46
private
:
47
IArena
& arena_;
48
MemoryLimiter
& memory_limiter_;
49
};
50
51
}
// namespace core
52
}
// namespace roc
53
54
#endif
// ROC_CORE_LIMITED_ARENA_H_
roc::core::IArena
Memory arena interface.
Definition
iarena.h:23
roc::core::LimitedArena::allocate
virtual void * allocate(size_t size)
Allocate memory after checking with the memory limiter.
roc::core::LimitedArena::deallocate
virtual void deallocate(void *ptr)
Deallocate previously allocated memory.
roc::core::LimitedArena::compute_allocated_size
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....
roc::core::LimitedArena::LimitedArena
LimitedArena(IArena &arena, MemoryLimiter &memory_limiter)
Initialize.
roc::core::LimitedArena::allocated_size
virtual size_t allocated_size(void *ptr) const
Returns how many bytes was allocated for given pointer returned by allocate(). Covers all internal ov...
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
iarena.h
Memory arena 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_arena.h
Generated by
1.17.0