- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在开发一个用于处理接近 1:1 微米:像素比的电路图片的程序,因此我在动态分配的各种 vector 中有相当多的元素(通过 constructor for CImg )。除此之外,我只分配了几个 Qt 小部件。
CImg<unsigned char> image(this->image.width(), this->image.height(), 1, 3, 0);
这就是它的出发点。
CImg(const unsigned int size_x, const unsigned int size_y,
const unsigned int size_z, const unsigned int size_c, const T& value) :
_is_shared(false) {
const unsigned long siz = (unsigned long)size_x*size_y*size_z*size_c;
if (siz) {
_width = size_x; _height = size_y; _depth = size_z; _spectrum = size_c;
try { _data = new T[siz]; /*thrown here*/ }
catch (...) {
_width = _height = _depth = _spectrum = 0; _data = 0;
throw CImgInstanceException(_cimg_instance
"CImg(): Failed to allocate memory (%s) for image (%u,%u,%u,%u).",
cimg_instance,
cimg::strbuffersize(sizeof(T)*size_x*size_y*size_z*size_c),
size_x, size_y, size_z, size_c);
}
fill(value);
}
else { _width = _height = _depth = _spectrum = 0; _data = 0; }
}
构造函数调用中的
image.width()
和 image.height()
分别约为 25000 和 900。这使得 siz
接近 6600 万。因此,分配了大约 66MB 的无符号字符。
谷歌搜索给了我一堆暗示内存碎片的结果。在使用高峰期,该程序会用掉 2GB。 Windows 肯定可以在剩余的 >6GB 内存中找到 66MB 的位置,这不可能是内存碎片,对吧?也就是说,它还能是什么?
我要补充一点,这只会在 Debug模式下编译后发生,而不是在 Release模式下编译后发生。
最佳答案
已修复。需要/LARGEADDRESSAWARE 来对抗 32 位内存限制。
谢谢@jdigital。
关于c++ - 'new' 在相对较小的分配上导致 std::bad_alloc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33967522/
这个错误的原因是什么?其实我不想受到之前测试用例结果的影响所以在测试用例开始时,我清空了队列以便每个测试用例都可以重新开始。 " #include #include using name
我的程序中出现了 bad_alloc 异常。 这些是限制条件: 1 #include #include #include class SuffixArray { std::vector
我在 digital ocean 上使用 node.js 并尝试运行文件上传/下载服务器。 为了确保服务器在后台运行并且不会因错误而退出,我使用了以下内容 nohup nodejs server.js
[前注:我已经阅读了 StackOverflow 中的现有线程。我的问题似乎没有] 我正在研究 Quake 2 MD2 格式。在新建一个指针数组后,我似乎得到了错误的分配。但是,如果我做一些可怕的指针
使用QAudioOut我试图按顺序播放存储在QByteArray中的数据...这在追加少量数据时起作用,但是当数据过多时,可以说是2到3个小时的RAW PCM从不同组合追加由于堆的大小不足以同时保存所
我是C++的新手,我真的很想使用Botan连接到硬件加密 token 。我不知道是否错过了libs或dlls的任何设置。 我基于Building Botan library in Windows 10
我正在用 C++ 编写一些使用 BFS 搜索迷宫的代码(我的主要语言是 Python,但我想稍微锻炼一下我的 C++ 大脑...),我偶然发现了这个奇怪的错误。 这里是相关的数据结构: struct
我必须为我的单元测试导致 bad_alloc(基本上,为了 100% 的代码覆盖率,我无法更改某些函数)。我该怎么办? 这是我的代码示例。我必须在这里的某个地方引起 bad_alloc。 bool i
在 c++ 中,分配内存时会发生 bad_alloc,或者至少我是这么理解的,但现在我在从数组读取内存时遇到此错误。我创建数组: int * possible = new int[ suma ]; 然
我遇到编译器错误: 错误 C2061:语法错误:标识符“bad_alloc” 我以前在其他项目中使用过下面的代码块,在 try block 中使用不同的内存分配,没有问题。我希望有人能向我解释为什么
我使用了这个伪代码: h := 1 /* Initialization of the pivot row */ k := 1 /* Initialization of the pivot colu
我四处寻找这个问题的解决方案,但找不到,所以我只好问问。我的程序是一个迷宫游戏,其中包含许多不同的房间,每个房间都使用指针链接到一个或多个相邻的房间。玩家从一个房间导航到另一个房间,直到找到导出。 当
我正在尝试递归地 segmentation 球体以在面上实现球面小波算法。虽然我有 8 GB 的可用内存,但我只能将二十面体 segmentation 为 9 个级别。我的问题是在构建我的球体时内存不
我从事一个游戏项目。最近,我们遇到了一个问题,当我们加载/卸载不同的场景大约 3 次时,我们捕获了“bad_alloc”异常。 每次加载场景时,我们首先将压缩的 .zip 文件夹加载到内存中,然后从中
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
当构造函数中抛出bad_alloc异常时,其中创建了多个对象,必须做些什么来清理内存。例如。 class Object { private: A * a; B * b;
我的程序抛出一个 std::bad_alloc。调试后发现是代码中抛出的 curFinalBucket->points.push_back(p); 其中点是一个 vector .在代码行之前,curF
我目前正在做一个 C++ 项目,现在我已经卡住了一段时间了。这是关于使用表达式模板和(至少对我来说)一个奇怪的 bad_alloc 的延迟评估。 如果您尝试下面的代码,您会注意到由于最后一次添加 b+
所以我有一个结构 struct float3 { float x, y, z; }; 我正在尝试创建一个函数来获取 x、y、z 值并将它们映射到键 0、1、2 以对应其各自的维度。我写了下面的
考虑这个简单的程序: #include #include int main(void) { const std::size_t size = 1 size_t_max / sizeof(i
我是一名优秀的程序员,十分优秀!