2.1 空间配置器的标准接口
allocator的必要接口:
allocator::value_type allocator::pointer allocator::const_pointer allocator::reference allocator::const_reference allocator::size_type allocator::difference_type //一个嵌套的class template(类模板), //class rebind<U>拥有唯一成员other(一个typedef,代表allocator<U>) allocator::rebind //默认的构造函数 allocator::allocator() //copy constructor(复制构造器) allocator::allocator(const allocator&) //泛化的copy constructor template <class U>allocator::allocator(const allocator<U>&) //解析函数 allocator::~allocator() //返回某个对象的地址。算式a.address(x)等同于&x pointer allocator::address(reference x) cosnt //返回某个cosnt对象的地址。算式a.address(x)等同于&x const_pointer allocator::address(const_reference x) const //配置空间,足以存储n个T对象。 //第二个参数是提示。实现上可能会利用它来增进区域性(locality),或完全忽略之 pointer allocator::allocate(size_type n,const void*=0) //归还先前配置的空间 void allocator::deallocate(pointer p,size_type n) //返回可成功配置的最大量 size_type allocator::max_size() const //等同于new((void*) p) T(x) void allocator::construct(pointer p,const T& x) //等同于p->~T() void allocator::destroy(pointer p)
2.2 具备次配置力(sub-allocation)的SGI空间配置器
时间: 2024-10-27 12:45:44