This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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

It would be possible for the compiler to implement this workaround
transparently, as an extension; i.e. if the new'd type has alignment
greater than MALLOC_ALIGN, use something like

  operator new (size_t size, enum align_tag, size_t align);

i.e. translate

  new Vector4[200];

into

  new (__gnu_cxx::aligned, __alignof (Vector4)) Vector4[200];

But this would interact badly with overriding the default operator new.

I think that if glibc is unwilling to change the default alignment for
malloc, it doesn't make any sense for libstdc++ to change it in operator
new.  The above workaround stands a good chance of breaking things if
implemented transparently.

So I think that the way to fix this problem is for users to implement the
workaround, possibly relying on the above operator new signature, to be
provided by libstdc++.  Vector4::operator new would then be simplified to

void *operator new (size_t size) 
{
   return operator new (size, __gnu_cxx::aligned, __alignof (Vector4));
}

Thoughts?

Jason


-- 


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]