[pool] Proper example of usage of pool allocator

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

Seweryn Habdank-Wojewódzki ha escrito:
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.
[...] Hi Seweryn, I haven't tested your code, but I noticed that you're using boost::fast_pool_allocator inside std::vectors: AFAIK, pool allocators can do little to improve the performance of vectors, since these data structures already have their elements arranged in contiguous chunks of memory. If you switched to a node-based container like vg. std::list I guess you would actually see some improvement when using the pool allocator. Just my 2c, Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

Hi again
Joaquín M? López Mu?oz wrote:
If you switched to a node-based container like vg. std::list I guess you would actually see some improvement when using the pool allocator.
I have switched to list using fast_pool_allocator and still nothing is improved. I do not demand any improvement, because algorithm can be slow. But still I am looking for design guides, when pool allocator will be better than standard one. Maybe many "erase" operation is a key for success of pool allocator? Best regards. -- |\/\/| Seweryn Habdank-Wojewódzki \/\/
participants (2)
-
Joaquín Mª López Muñoz
-
Seweryn Habdank-Wojewódzki