如何对齐结构数组,每个结构都需要对齐(SSE)
How to align array of structs, each require alignment (SSE)
我有一个struct alignedStruct
,它需要特殊对齐(SEE ext):
void* operator new(size_t i) { return _aligned_malloc(i, 16); }
void operator delete(void* p) { _aligned_free(p); }
这种对齐方式适用于alignedStruct
的唯一对象/指针,但后来我尝试这样做:
alignedStruct * arr = new alignedStruct[count];
我的应用程序崩溃了,问题肯定是关于"阵列对齐"(正好在前一行):
0xC0000005: Access violation reading location 0xFFFFFFFF.
这样的崩溃发生在约60%的时间内,也表明问题并不典型。
我相信您想要的是放置new
,它允许您正确地使用带有构造函数的_aligned_malloc
。或者,您可以过载operator new[]
和operator delete[]
。
void* operator new[] (std::size_t size)
{
void * mem = _aligned_malloc(size, 16);
if(mem == nullptr)
throw std::bad_alloc;
return mem;
}
相关文章:
- OPENCL结构对齐错误
- 数据结构对齐:为什么Char和STD :: String的数组不同
- interpret_cast和结构对齐
- 结构对齐填充、最大填充大小和结构成员顺序
- 与此类结构对齐是否以C 标准为标准
- 64位Windows API结构对齐导致命名管道上出现“拒绝访问”错误
- 如何检测/查找 64 位结构对齐问题
- 检索数据结构对齐信息
- C# 中的结构对齐
- 视觉C++中的结构对齐
- 为什么iOS中的结构对齐方式不同
- 内存对齐-结构的总大小是结构对齐的倍数,而不是处理大小
- 内存对齐到结构-对齐大小等于最大成员大小
- 结构对齐 C/C++
- C与C++结构对齐
- 警告 C4121 行为和结构对齐 (Visual Studio 2010)
- C/C++ 中的对象/结构对齐
- #pragma pack,模板类型和结构对齐
- Fscanf和结构对齐
- c++中的结构对齐和填充