In the previous recipe, you have learned how to use C++11 to allocate aligned memory. The question now is: how do we know that memory is properly aligned? This recipe will teach you about this.
Checking whether the memory allocated is aligned
How to do it...
We'll be using the previous program, and by modifying it a little, we'll see how to check whether a pointer is aligned or not:
- Let's modify the previous program, as follows:
#include <type_traits>
#include <iostream>
using intAligned8 = std::aligned_storage<sizeof(int), 8>::type;
using intAligned4 = std::aligned_storage<sizeof(int), 4>::type;
int main()
{
intAligned8 i; new(&i) int();
intAligned4 j; new (&j) int()...