Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
aligned_storage.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 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/aligned_storage.h
10//! @brief Aligned storage.
11
12#ifndef ROC_CORE_ALIGNED_STORAGE_H_
13#define ROC_CORE_ALIGNED_STORAGE_H_
14
15#include "roc_core/align_ops.h"
16#include "roc_core/stddefs.h"
17
18namespace roc {
19namespace core {
20
21//! Fixed-size maximum-aligned storage.
22template <size_t Size> class AlignedStorage {
23public:
24 //! Get storage size.
25 static size_t size() {
26 return sizeof(Memory);
27 }
28
29 //! Get storage memory.
30 const void* memory() const {
31 return memory_.payload;
32 }
33
34 //! Get storage memory.
35 void* memory() {
36 return memory_.payload;
37 }
38
39private:
40 union Memory {
41 AlignMax alignment;
42 char payload[Size != 0 ? Size : 1];
43 };
44
45 Memory memory_;
46};
47
48} // namespace core
49} // namespace roc
50
51#endif // ROC_CORE_ALIGNED_STORAGE_H_
Alignment operations.
Fixed-size maximum-aligned storage.
const void * memory() const
Get storage memory.
void * memory()
Get storage memory.
static size_t size()
Get storage size.
Shared ownership intrusive pointer.
Definition shared_ptr.h:32
Root namespace.
Commonly used types and functions.
Maximum aligned data unit.
Definition align_ops.h:21