bad_alloc on vector.push() and vector.reserve()
bad_alloc on vector.push() and vector.reserve()
我正在尝试构建大小为 772538368
的 GLfloat
向量。在做push_back()
时,我遇到了bad_alloc
错误。
检查完这个问题后,我试图为向量reserve()
内存。但是,现在我在尝试reserve()
本身时遇到了同样的错误。
在我的机器上,vector.max_size: 1073741823
,这比我需要的要大。在其他细节上,我在Windows 2015上使用VS 10。另外,请在下面找到相关的代码片段。
我应该怎么做才能解决这个问题?
相关代码片段:
int main() {
vector<GLfloat> targetVector;
targetVector.reserve(772538368); //Attempt2 to reserve. Also tried resize()
vector<vector<vector<GLshort>>> my3DimensionalData;
//build my3DimensionalData //no problem here.
//targetVector.reserve(772538368); //Attempt1 to reserve.
for (GLint rowIndex = 0; rowIndex < numberOfRows; rowIndex++)
{
for (GLint colIndex = 0; colIndex < numberOfCols; colIndex++)
{
for (GLint depthIndex = 0; depthIndex < numberOfDepths; depthIndex++)
{
//perform gymnastic here on my3DimensionalData and get data.
/*initially I was getting bad_alloc while pushing back
*elements in the following block.
*This led to Attempt1 and Attempt2 as shown above.
*/
targetVector.push_back(data1);
targetVector.push_back(data2);
...
targetVector.push_back(data7);
}
}
}
}
你很可能需要一个64位的构建。您需要超过 3 GB 的连续内存,这几乎是 4GB 内存空间的全部。
相关文章:
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- 在c++中用vector填充一个简单的动态数组
- vector.resize()中的分配错误
- 使用std::vector的OpenCL矩阵乘法
- Bjarne Stroustrup Book - Vector and For loop - 将不起作用
- C++ vector.begin() and vector[0]
- Boost mpl::vector and hana
- BOOST_FOREACH and a vector
- vector::push_back and std::move
- Natvis Visual Studio 2012 Boost Vector and Matrix
- vector::erase and reverse_iterator
- c++ mysqlpp::storequeryresult and std::vector
- STL vector: resize() and assign()
- std::vector::emplace_back and std::move
- C++ error: Double and 3d Vector
- Vector and push_back() behavior
- std::vector and std::min behavior
- std::vector and Constructors
- bad_alloc on vector.push() and vector.reserve()
- std::vector vs std::list for insertion frequency and dynamic