I am using STXXL Library's stxxl::vector in my code as :
struct B
{
typedef stxxl::VECTOR_GENERATOR<float>::result vector;
vector content;
};
And then creating many instances of the above declared Structure in a loop using the following code snippet :
for(i=0;i<50;i++)
{
B* newVect= new B();
// Passing the above '*newVect' to some other function
}
But this snippet will not create 'newVect' beyond certain number(30: in this case)
However, I tried the same thing by just replacing "stxxl:Vector" with some other In Memory datatypes as :
struct B
{
float a,b,c;
int f,g,h;
};
Above created Structure works fine even for "100000" new instances as:
for(i=0;i<100000;i++)
{
B* newVect= new B();
// Passing the above '*newVect' to some other function
}
with every system resource remaining same.
Please help me with this.
Can "stxxl:Iterators" help here or work as an alternative?
What kind of behavior do 'stxxl:vector' have in this case?
UPDATE
Tried removing the function call from each iteration and putting it altogether outside the loop but no help. Example Code:
#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;
}
Each stxxl::vector costs a specific amount of internal memory, since it is basically a paging system for blocks in external memory.
With the default settings, this is 8 (CachePages) * 4 (PageSize) * 2 MiB (BlockSize) = 64 MiB of RAM per stxxl::vector.
So, you are basically running out of RAM.