Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Loading...
Searching...
No Matches
buffer_factory.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/buffer_factory.h
10//! @brief Buffer factory.
11
12#ifndef ROC_CORE_BUFFER_FACTORY_H_
13#define ROC_CORE_BUFFER_FACTORY_H_
14
17#include "roc_core/shared_ptr.h"
18#include "roc_core/slab_pool.h"
19
20namespace roc {
21namespace core {
22
23template <class T> class Buffer;
24
25//! Buffer factory.
26template <class T> class BufferFactory : public core::NonCopyable<> {
27public:
28 //! Initialization.
29 BufferFactory(IAllocator& allocator, size_t buff_size, bool poison)
30 : pool_(allocator, sizeof(Buffer<T>) + sizeof(T) * buff_size, poison)
31 , buff_size_(buff_size) {
32 }
33
34 //! Get buffer size (number of elements in buffer).
35 size_t buffer_size() const {
36 return buff_size_;
37 }
38
39 //! Allocate new buffer.
41 return new (pool_) Buffer<T>(*this);
42 }
43
44private:
45 friend class FactoryAllocation<BufferFactory>;
46
47 void destroy(Buffer<T>& buffer) {
48 pool_.destroy_object(buffer);
49 }
50
51 SlabPool pool_;
52 size_t buff_size_;
53};
54
55} // namespace core
56} // namespace roc
57
58#endif // ROC_CORE_BUFFER_FACTORY_H_
Allocation policies.
BufferFactory(IAllocator &allocator, size_t buff_size, bool poison)
Initialization.
size_t buffer_size() const
Get buffer size (number of elements in buffer).
SharedPtr< Buffer< T > > new_buffer()
Allocate new buffer.
Allocation policy for objects (de)allocated using speciailized factory.
Memory allocator interface.
Definition iallocator.h:23
Base class for non-copyable objects.
Definition noncopyable.h:23
Shared ownership intrusive pointer.
Definition shared_ptr.h:32
void destroy_object(T &object)
Destroy object and deallocate its memory.
Definition slab_pool.h:73
Root namespace.
Non-copyable object.
Shared ownership intrusive pointer.
Slab pool.