我在我的代码中使用 STXXL 库的 stxxl::vector 作为:
struct B
{
typedef stxxl::VECTOR_GENERATOR<float>::result vector;
vector content;
};
然后使用以下代码片段在循环中创建上述声明的结构的许多实例:
for(i=0;i<50;i++)
{
B* newVect= new B();
// Passing the above '*newVect' to some other function
}
但是这个片段不会创建超过一定数量的“newVect”(30:在这种情况下)
但是,我通过将“stxxl:Vector”替换为其他一些内存数据类型来尝试相同的事情:
struct B
{
float a,b,c;
int f,g,h;
};
即使对于“100000”个新实例,上面创建的结构也可以正常工作:
for(i=0;i<100000;i++)
{
B* newVect= new B();
// Passing the above '*newVect' to some other function
}
每个系统资源保持不变。
请帮我解决一下这个。
“stxxl:Iterators”可以在这里提供帮助或作为替代方案吗?
在这种情况下,'stxxl:vector' 有什么样的行为?
更新
尝试从每次迭代中删除函数调用并将其完全放在循环之外,但没有帮助。示例代码:
#include <stxxl/vector>
#include <iostream>
using namespace std;
struct buff
{
typedef stxxl::VECTOR_GENERATOR<float>::result vector;
vector content;
};
struct par
{
buff* b[35];
};
void f(par *p)
{
for(int h=0;h<35;h++)
{
std::cout<<endl<<"In func: "<<(*p).b[h];
}
}
int main()
{
par parent;
for(int h=0;h<35;h++)
{
buff* b=new buff();
parent.b[h]=b;
cout<<endl<<"IN main: "<<parent.b[h];
}
cout << endl << endl;
f(&parent);
return 0;
}