#include <iostream>
#include <vector>
#include <ext\pool_allocator.h>
using namespace std;
template<typename Alloc>
void cookie_test(Alloc alloc, size_t n) {
typename Alloc::value_type *p1,*p2,*p3;
p1 = alloc.allocate(n);
p2 = alloc.allocate(n);
p3 = alloc.allocate(n);
cout << "p1= " << p1 << '\t' << "p2= " << p2 << '\t' << "p3= " << p3 << endl;
alloc.deallocate(p1, sizeof(typename Alloc::value_type));
alloc.deallocate(p2, sizeof(typename Alloc::value_type));
alloc.deallocate(p3, sizeof(typename Alloc::value_type));
}
int main() {
cout << sizeof(__gnu_cxx::__pool_alloc<int>) << endl;
vector<int, __gnu_cxx::__pool_alloc<int> > vecPool;
cookie_test(__gnu_cxx::__pool_alloc<double>(), 1);
//相距08h(表示不带cookie)
cout << endl;
cout << sizeof(std::allocator<int>) << endl;
vector<int, std::allocator<int> > vec;
cookie_test(std::allocator<double>(), 1);
//相距10h(表示带cookie)
return 0;
}
G4.9的allocator只是以::operator new和::operator delete完成allocate()和deallocate(),没有任何特殊设计
欲使用std::allocatoe以外的allocator,就得自行//include <ext/...>