1. VC6中的std::allocator

VC6中的std::allocator源码实现如下图:

1584426117065

从图中可以发现,VC6中的std::allocator并没有进行memory pool这类的处理,直接在里面调用operator new(),进而调用::operator new,然后malloc来实现的。

1584426383840

2. BC中的std::allocator

没有安装BC5,所以就不查看BC的源码来进行验证了,直接看课件。

1584426545705

3. GCC 中的std::allocator

然后再来看GCC2.9中的实现。

1584426703551

从前面的几个实现都可以发现,它们的std::allocator都是直接调用的operator new, 并没有进行memory pool的处理。但是在GCC2.9中发现一点值得注意的是,STL中的容器并没有使用这个std::allocator, 而是使用的名为std::alloc的一个allocator.

1584427026740

而这个std::alloc其实是大有文章的。由于GCC2.9已经比较久远了,我们看看我们的GCC4.9中是否还是这样的。GCC4.9中没有了alloc,但是在GCC4.9中增加了很多的extended allocator, 在这些extended allocator中存在一个叫做__pool_allocallocator, 它实际上就是GCC2.9中的alloc。转回来看看GCC4.9中的std::alloctor,出奇的一致GCC4.9中的std::allocator也是没有任何特殊的处理,直接使用的operator new

1584427290231

4. 总结

1584429212123