Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Loading...
Searching...
No Matches
heap_allocator.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017 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/heap_allocator.h
10//! @brief Heap allocator implementation.
11
12#ifndef ROC_CORE_HEAP_ALLOCATOR_H_
13#define ROC_CORE_HEAP_ALLOCATOR_H_
14
15#include "roc_core/atomic.h"
16#include "roc_core/iallocator.h"
18
19namespace roc {
20namespace core {
21
22//! Heap allocator implementation.
23//!
24//! Uses global operator new[] and operator delete[].
25//!
26//! The memory is always maximum aligned. Thread-safe.
27class HeapAllocator : public IAllocator, public NonCopyable<> {
28public:
29 //! Enable panic on leak in destructor, for all instances.
30 static void enable_panic_on_leak();
31
34
35 //! Get number of allocated blocks.
36 size_t num_allocations() const;
37
38 //! Allocate memory.
39 virtual void* allocate(size_t size);
40
41 //! Deallocate previously allocated memory.
42 virtual void deallocate(void*);
43
44private:
45 static int panic_on_leak_;
46
47 Atomic<int> num_allocations_;
48};
49
50} // namespace core
51} // namespace roc
52
53#endif // ROC_CORE_HEAP_ALLOCATOR_H_
Atomic.
Atomic integer. Provides sequential consistency. For a fine-grained memory order control,...
Definition atomic.h:26
Heap allocator implementation.
size_t num_allocations() const
Get number of allocated blocks.
static void enable_panic_on_leak()
Enable panic on leak in destructor, for all instances.
virtual void * allocate(size_t size)
Allocate memory.
virtual void deallocate(void *)
Deallocate previously allocated memory.
Memory allocator interface.
Definition iallocator.h:23
Base class for non-copyable objects.
Definition noncopyable.h:23
Memory allocator interface.
Root namespace.
Non-copyable object.