C/C++ API Reference
Loading...
Searching...
No Matches
pw_alignment

Oveview

Natural object alignment, guaranteed. Main docs: https://pigweed.dev/pw_alignment.

Classes

struct  pw::NaturallyAligned< T >
 

Typedefs

template<typename T >
using pw::AlignedAtomic = std::atomic< NaturallyAligned< T > >
 

Functions

 pw::NaturallyAligned< T >::NaturallyAligned (const T &t)
 
template<class U >
 pw::NaturallyAligned< T >::NaturallyAligned (const U &u)
 
NaturallyAlignedpw::NaturallyAligned< T >::operator= (T other)
 

Typedef Documentation

◆ AlignedAtomic

template<typename T >
using pw::AlignedAtomic = typedef std::atomic<NaturallyAligned<T> >

Ensures the object held by std::atomic is naturally aligned. This enables the compiler to replace libcalls to atomic functions with native instructions when appropriate. AlignedAtomic is a convenience wrapper.

Example:

#include "pw_alignment/alignment.h"
std::atomic< NaturallyAligned< T > > AlignedAtomic
Definition: alignment.h:101

std::optional<bool> has a size of 2 but alignment of 1, which would normally lower to an __atomic_* libcall, but pw::NaturallyAligned in std::atomic tells the compiler to align the object to 2 bytes, which satisfies the requirements for replacing __atomic_* with native instructions.