数组错误 - 访问冲突读取位置0xffffffff [英] Array Error - Access violation reading location 0xffffffff

查看:1494
本文介绍了数组错误 - 访问冲突读取位置0xffffffff的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以前使用SIMD运算符来提高我的代码的效率,但我现在面临一个新的错误,我不能解决。对于这个任务,速度是至关重要的。

I have previously used SIMD operators to improve the efficiency of my code, however I am now facing a new error which I cannot resolve. For this task, speed is paramount.

在导入数据之前,数组的大小是不知道的,可能非常小(100个值)或巨大10百万值)。对于后一种情况,代码工作正常,但是我遇到一个错误,当我使用少于130036数组值。

The size of the array will not be known until the data is imported, and may be very small (100 values) or enormous (10 million values). For the latter case, the code works fine, however I am encountering an error when I use fewer than 130036 array values.

有没有人知道是什么导致这个问题,如何以解决它?

Does anyone know what is causing this issue and how to resolve it?

我附加了(测试过的)代码,稍后将在更复杂的函数中使用。错误发生在arg1List [i] = ...

I have attached the (tested) code involved, which will be used later in a more complicated function. The error occurs at "arg1List[i] = ..."

#include <iostream>
#include <xmmintrin.h>
#include <emmintrin.h>

void main()
{
    int j;
    const int loop = 130036;
    const int SIMDloop = (int)(loop/4);
    __m128 *arg1List = new __m128[SIMDloop];

    printf("sizeof(arg1List)= %d, alignof(Arg1List)= %d, pointer= %p", sizeof(arg1List), __alignof(arg1List), arg1List);
    std::cout << std::endl;

    for (int i = 0; i < SIMDloop; i++)
    {
        j = 4*i;
        arg1List[i] = _mm_set_ps((j+1)/100.0f, (j+2)/100.0f, (j+3)/100.0f, (j+4)/100.0f);
    }
}


推荐答案

是原因。


MOVAPS - 移动对齐打包的单精度浮点值

MOVAPS--Move Aligned Packed Single-Precision Floating-Point Values

[...]操作数必须在16字节边界上对齐,否则将生成一般保护异常(#GP)。

[...] The operand must be aligned on a 16-byte boundary or a general-protection exception (#GP) will be generated.

您可以在对齐您的指针后看到问题已解决:

You can see the issue is gone as soon as you align your pointer:

__m128 *arg1List = new __m128[SIMDloop + 1];
arg1List = (__m128*) (((int) arg1List + 15) & ~15);

这篇关于数组错误 - 访问冲突读取位置0xffffffff的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆