小编Adr*_*chi的帖子

加载/清除大量数据时,std :: vector变得越来越慢

问题

我有一个非常复杂的图像处理应用程序,其中一个子模块需要将巨大的二进制位图加载到内存中.实际上高达96 GB(意味着888 888 x 888 888像素图像).磁盘是2xSSD raid0,读/写速率约为1 GB/s.它将图像加载到带有字节的向量的智能指针的向量(每个元素表示位图中的一行)中(每个元素代表8个像素).这里的奇怪问题是,在重复加载和清除向量之后(我看到内存实际上被填充并清除而没有内存泄漏),每次迭代似乎需要越来越长的时间.特别清除内存需要很长时间.

测试

我做了一些简单的测试应用程序来测试这个孤立的,从不同的角度.用原始指针替换智能指针给出了同样奇怪的行为.然后我尝试使用原生数组而不是矢量,这就是诀窍.在100次迭代加载/清除之后24 GB时间在使用向量时急剧增加,而阵列实现在时间上是稳定的.下面是测试应用程序填充内存与24 GB垃圾而不是加载实际图像,具有相同的结果.在具有128 GB RAM的Windows 10 Pro上进行的测试,并使用Visual Studio 2013 Update 5构建.

此函数使用向量进行加载/清除:

void SimpleLoadAndClear_Vector(int width, int height) {
    time_t start_time, end_time;

    // Load memory
    time(&start_time);
    cout << "Loading image into memory...";
    auto width_bytes = width / 8;
    auto image = new vector<vector<unsigned char>*>(height);
    for (auto y = 0; y < height; y++) {
        (*image)[y] = new vector<unsigned char>(width_bytes);
        auto row_ptr = (*image)[y];
        for (auto b = 0; b < width_bytes; …
Run Code Online (Sandbox Code Playgroud)

c++ memory windows arrays vector

6
推荐指数
1
解决办法
143
查看次数

std :: string ==不工作?

当我做:

std::string name = targetBone->getName();
    if(name == "Pelvis")
    {
        return;
    }
Run Code Online (Sandbox Code Playgroud)

我明白了:

Error 1 error C2678: binary '==' : no operator found which takes a left-hand operand of type 'std::string' (or there is no acceptable conversion)

我该如何解决这个错误?

谢谢

c++ visual-studio

2
推荐指数
1
解决办法
2650
查看次数

标签 统计

c++ ×2

arrays ×1

memory ×1

vector ×1

visual-studio ×1

windows ×1