simple_alloc只是对配置器的简单包装
代码如下:
1 #include "__malloc_alloc_template.h" 2 #include "__defalut_alloc_template.h" 3 4 template<typename T, typename Alloc> 5 class simple_alloc 6 { 7 public: 8 static T* allocate(size_t n) 9 { 10 return 0 == n ? 0 : (T*)Alloc::allocate(n * sizeof(T)); 11 } 12 static T* allocate(void) 13 { 14 return (T*) Alloc::allocate(sizeof(T)); 15 } 16 static void deallocate(T* p, size_t n) 17 { 18 if(0 != n) Alloc::deallocate(p, n * sizeof(T)); 19 } 20 static void deallocate(T* p) 21 { 22 Alloc::deallocate(p, sizeof(T)); 23 } 24 };