Re: : impossible alignment requirements?
On Nov 13, 6:03 pm, levick...@sezampro.yu wrote:
What should one do with this code?
class foo
{
public:
__m128 vec;
...
foo(void)
{
vec = _mm_setzero_ps();
}
};
foo *p = new foo[10]; // [corrected]
Since the foo type has an alignment requirement of 16, new should
return properly aligned memory for that type.
If it doesn't, then it's an implementation issue.
It is true however that it is quite hard to implement it correctly,
since the standard asks operator new to return memory properly aligned
for any type ; and raising that default alignment could have an
important impact on efficiency.
A simple solution is to not use new. Which is quite a shame because
you lose the possibility of calling delete polymorphically.
As for the stack, if the compiler doesn't align foo as requested, it
is a pure implementation issue. In your case, char[32] has an
alignment requirement of 1, so it's not surprising if it isn't.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]