首页 > 代码库 > Ch2 空间配置器(allocator) ---笔记

Ch2 空间配置器(allocator) ---笔记

2.1 空间配置器的标准接口

allocator的必要接口:

allocator::value_typeallocator::pointerallocator::const_pointerallocator::referenceallocator::const_referenceallocator::size_typeallocator::difference_type//一个嵌套的class template(类模板),//class rebind<U>拥有唯一成员other(一个typedef,代表allocator<U>)allocator::rebind//默认的构造函数allocator::allocator()//copy constructor(复制构造器)allocator::allocator(const allocator&)//泛化的copy constructortemplate <class U>allocator::allocator(const allocator<U>&)//解析函数allocator::~allocator()//返回某个对象的地址。算式a.address(x)等同于&xpointer allocator::address(reference x) cosnt//返回某个cosnt对象的地址。算式a.address(x)等同于&xconst_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空间配置器

Ch2 空间配置器(allocator) ---笔记