Table of Contents
基本思想
C++和C最大的区别在于面向对象的引入,因此,相对于C的内存管理,C++多了一个对象构造的过程,因此,标准库使用std::allocator模板类来管理内存,STL的空间配置器allocator明确地将内存分配和对象构造作为两个独立的步骤,内存分配由alloc::allocate()/alloc::deallocate()负责,对象构造由::construct()/::destroy()负责。
std::allocator接口
namespace std
{
template<typename T>
class allocator
{
public:
T* allocate(std::size_t n, const void* hint);
void deallocate(T* p, std::size_t n);
template<typename T, typename... Args>
void construct(T* p, Args&&... args