我意外地发现,STL向量可以按以下方式定义:
vector < float > test;
test.resize(10000 * 10000 * 5);
相比以下定义,占用的RAM空间显著更少:
std::vector<std::vector<std::vector< float > > > test;
test.resize(10000);
for(int i = 0;i < 10000;i++)
{
test[i].resize(10000);
for(int j = 0;j < 10000;j++)
{
test[i][j].resize(5);
}
}
线性向量法(顶部)使用正确数量的RAM(2GB),就像手动计算一样。那么我的问题是,为什么3D向量比线性向量使用更多的RAM,在这个例子中,我发现它显著地多(约4GB)。
resize
传递浮点数值? - Jonathon Reinhart