MCPcopy Create free account
hub / github.com/OSVR/OSVR-Core / computeAlignmentPadding

Function computeAlignmentPadding

inc/osvr/Common/AlignmentPadding.h:49–64  ·  view source on GitHub ↗

@brief Given an alignment in bytes, and a current size of a buffer, return the number of bytes of padding required to align the next field to be added to the buffer at the desired alignment within that buffer. That is, return some padding such that (currentSize + padding) % alignment == 0 for alignment > 1. @param alignment Alignment in bytes: both 0 and 1 are accepted to mean "no alignment" @pa

Source from the content-addressed store, hash-verified

47 /// "no alignment"
48 /// @param currentSize Current number of bytes in a buffer
49 inline size_t computeAlignmentPadding(size_t alignment,
50 size_t currentSize) {
51 size_t ret = 0;
52 if (2 > alignment) {
53 /// No alignment requested
54 return ret;
55 }
56 auto leftover = currentSize % alignment;
57 if (leftover == 0) {
58 /// Buffer is already aligned
59 return ret;
60 }
61 /// Buffer needs some padding
62 ret = alignment - leftover;
63 return ret;
64 }
65} // namespace common
66} // namespace osvr
67

Callers 5

spaceRequiredMethod · 0.85
spaceRequiredMethod · 0.85
readAlignedMethod · 0.85
readBytesAlignedMethod · 0.85
appendAlignedMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected