2014年10月2日
摘要: 自己实现Allocator并不难,其实只需要改变allocate和deallocate,来实现自己的内存分配策略。 下面是一个std::allocator的模拟实现 #ifndef ALLOCATOR_HPP #define ALLOCATOR_HPP #include #include template class Allocator { public: typ... 阅读全文
posted @ 2014-10-02 17:18 inevermore 阅读(551) 评论(0) 推荐(0) 编辑
摘要: 上一篇我们提到了new运算符以及它的工作步骤,其实无非是把两项工作独立出来:1.申请原始内存2.执行构造函数delete也涉及了两个工作:1.执行析构函数2.释放原始内存其实标准库提供了另外一种更加高级的手段实现内存的分配和构造,就是std::allocator的职责。allocator提供了四个操... 阅读全文
posted @ 2014-10-02 17:11 inevermore 阅读(1227) 评论(0) 推荐(0) 编辑