
Hi!
Can any one show me the proper example of usage of pool allocator.
I have two examples (code below) and usage of pool consumes a lot of memory,
and nothing is faster/better/etc.
So what should be a design goal for using pool allocator?
Kind regards.
The code without allocator:
#include <vector>
#include <iostream>
#include <algorithm>
#include <iterator>
namespace primes
{
template < typename T >
void PrimesLE( T const Limit, std::vector<T> & result ) {
using namespace std;
typedef vector<T> cont_t;
result.clear();
result.resize(static_cast<typename cont_t::size_type>(Limit/2+1));
result[0] = static_cast<T>(2);
typename cont_t::iterator pos = result.begin();
T lim = 0;
T sq = 4;
T j = 1;
for (T counter = 3; counter <= Limit; counter += 2 ) {
if ( counter >= sq ) {
++lim;
sq = result[lim] * result[lim];
}
T f = 1;
for ( ; f < lim; ++f ) {
if ( counter % result[f] == 0 )
break;
}
if ( f >= lim ) {
result[j++] = counter;
}
}
return;
}
}
int main()
{
using namespace std;
typedef vector<int> Vi;
Vi p;
primes::PrimesLE(100000000,p);
//Vi::const_iterator pos = p.begin();
//Vi::const_iterator const end = p.end();
//for ( ; pos != end && *pos > 0 ; ++pos ) {
// cout << *pos << endl;
//}
cout << "Done" << endl;
cin.get();
}
The same code with allocator:
#include <vector>
#include <iostream>
#include <algorithm>
#include <iterator>
#include