Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
heap_allocator.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Roc 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"
17 #include "roc_core/noncopyable.h"
18 
19 namespace roc {
20 namespace 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.
27 class HeapAllocator : public IAllocator, public NonCopyable<> {
28 public:
29  ~HeapAllocator();
30 
31  //! Allocate memory.
32  virtual void* allocate(size_t size);
33 
34  //! Deallocate previously allocated memory.
35  virtual void deallocate(void*);
36 
37  //! Get number of allocated blocks.
38  size_t num_allocations() const;
39 
40 private:
41  Atomic num_allocations_;
42 };
43 
44 } // namespace core
45 } // namespace roc
46 
47 #endif // ROC_CORE_HEAP_ALLOCATOR_H_
Memory allocator interface.
Definition: iallocator.h:23
virtual void * allocate(size_t size)
Allocate memory.
Root namespace.
Atomic integer.
Definition: atomic.h:21
Base class for non-copyable objects.
Definition: noncopyable.h:23
Atomic integer.
Heap allocator implementation.
Non-copyable object.
size_t num_allocations() const
Get number of allocated blocks.
virtual void deallocate(void *)
Deallocate previously allocated memory.
Memory allocator interface.