我正在使用 CreateFile2 和 WriteFile 创建和写入文件,然后使用 readfile 一次将 16 个字节读取到 __m128i 中,然后对其执行 simd 操作。在调试模式下工作正常,但在发布模式下抛出拒绝访问 (0xc0000005) 错误代码。以我的经验,当我试图将非 16 字节对齐的东西推入 16 字节对齐的东西时,就会发生这种情况。但是,我不确定缺乏 16 字节对齐首先在哪里引起了它的丑陋。
#define simd __m128i
它在 CreateFile2() 调用中吗?
_CREATEFILE2_EXTENDED_PARAMETERS extend = { 0 };
extend.dwSize = sizeof(CREATEFILE2_EXTENDED_PARAMETERS);
extend.dwFileAttributes = FILE_ATTRIBUTE_NORMAL;
extend.dwFileFlags = /*FILE_FLAG_NO_BUFFERING |*/ FILE_FLAG_OVERLAPPED;
extend.dwSecurityQosFlags = SECURITY_ANONYMOUS;
extend.lpSecurityAttributes = nullptr;
extend.hTemplateFile = nullptr;
hMappedFile = CreateFile2(
testFileName.c_str(),
GENERIC_READ | GENERIC_WRITE,
0,
OPEN_ALWAYS,
&extend);
...在 WriteFile() 调用中?
_OVERLAPPED positionalData;
positionalData.Offset = 0;
positionalData.OffsetHigh = 0;
positionalData.hEvent = 0;
bool writeCheck = WriteFile(
hMappedFile,
&buffer[0],
vSize,
NULL,
&positionalData);
...在以后的 ReadFile() 调用中?
const simd* FileNodePointer(
_In_ const uint32_t index) const throw()
{
std::vector<simd> Node(8);
_OVERLAPPED positionalData;
positionalData.Offset = index;
positionalData.OffsetHigh = 0;
positionalData.hEvent = 0;
ReadFile(
hMappedFile,
(LPVOID)&Node[0],
128,
NULL,
&positionalData);
return reinterpret_cast<const simd*>(&Node[0]);
}
如何在此处强制执行 16 字节对齐?
谢谢!