[Bug c++/15795] No way to teach operator new anything about alignment requirements

jason at redhat dot com gcc-bugzilla@gcc.gnu.org
Tue Jun 8 18:05:00 GMT 2004


------- Additional Comments From jason at redhat dot com  2004-06-08 18:05 -------
Subject: Re:  No way to teach operator new anything about
 alignment requirements

And again, without the extra whitespace (sorry):

#include <xmmintrin.h>
#include <stdio.h>
#include <stdlib.h>
#include <new>

class Vector4
{
public:
  Vector4() { vec = _mm_setzero_ps(); }

  void *operator new (size_t);
  void *operator new[] (size_t size) { return operator new (size); }

  __m128 vec;
};

void *Vector4::operator new (size_t size)
{
  void *p;
  int r = posix_memalign (&p, __alignof (Vector4), size);
  if (r)
    throw std::bad_alloc ();
  return p;
}

int main(int argc, char **argv)
{
  Vector4 *foo = new Vector4[200*200];
  delete foo;
}


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15795



More information about the Gcc-bugs mailing list