Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Loading...
Searching...
No Matches
align_ops.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/align_ops.h
10//! @brief Alignment operations.
11
12#ifndef ROC_CORE_ALIGN_OPS_H_
13#define ROC_CORE_ALIGN_OPS_H_
14
16#include "roc_core/stddefs.h"
17
18namespace roc {
19namespace core {
20
21//! Alignment operations.
22class AlignOps {
23public:
24 //! Get maximum alignment for current platform.
25 static inline size_t max_alignment() {
27 }
28
29 //! Return size aligned to maximum alignment.
30 static inline size_t align_max(size_t size) {
31 return align_as(size, max_alignment());
32 }
33
34 //! Return size aligned to given alignment.
35 static inline size_t align_as(size_t size, size_t alignment) {
36 if (alignment == 0) {
37 return size;
38 }
39
40 if (size % alignment != 0) {
41 size += alignment - size % alignment;
42 }
43
44 return size;
45 }
46
47 //! Return padding needed for maximum alignment.
48 static inline size_t pad_max(size_t size) {
49 return pad_as(size, max_alignment());
50 }
51
52 //! Return padding needed for given alignment.
53 static inline size_t pad_as(size_t size, size_t alignment) {
54 if (alignment == 0) {
55 return 0;
56 }
57
58 size_t new_size = size / alignment * alignment;
59 if (new_size < size) {
60 new_size += alignment;
61 }
62
63 return (new_size - size);
64 }
65};
66
67} // namespace core
68} // namespace roc
69
70#endif // ROC_CORE_ALIGN_OPS_H_
Aligned storage.
Alignment operations.
Definition: align_ops.h:22
static size_t pad_max(size_t size)
Return padding needed for maximum alignment.
Definition: align_ops.h:48
static size_t align_as(size_t size, size_t alignment)
Return size aligned to given alignment.
Definition: align_ops.h:35
static size_t pad_as(size_t size, size_t alignment)
Return padding needed for given alignment.
Definition: align_ops.h:53
static size_t align_max(size_t size)
Return size aligned to maximum alignment.
Definition: align_ops.h:30
static size_t max_alignment()
Get maximum alignment for current platform.
Definition: align_ops.h:25
static size_t size()
Get storage size.
Root namespace.
Commonly used types and functions.