Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Used alignof in compliant example.

...

Code Block
bgColor#ccccff
langcpp
#include <new>
#include <stdlib.h>

struct alignas (32) Vector {
  char elems [32];
  static void* operator new (size_t);
  static void operator delete (void *p) {
    free (p);
  }
};

void* Vector::operator new (size_t nbytes) {
  if (void *p = aligned_alloc (32alignof (Vector), nbytes))
    return p;
  throw std::bad_alloc ();
}

Vector* f() {
  Vector *pv = new Vector ();
  return pv;
}

...