stl里面的容器里的allocator是如何能够接管operator new的?
我们一般new一个对象,申请内存的过程是operator new完成的,那么stl中的allocator是如何接管operator new完成内存申请的工作呢?对象的内存申请权是如何转移的?我看stl里面也没有重载operator new呀,另外如果在栈上生成我们的stl对象,也会经过allocator吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
In the formal c++, there is no such term called STL, STL is never an abbreviation of Standard Library or Standard Template Library. You can also refer to another my answer here. Yes, Allocators were invented by Alexander Stepanov. But his original library has been out of date and some components are adopted by the standard library.
From n4714 23.10.10.1 allocator members
There is no term stack in c++(only stack unwinding, which is not relevant here), in c, there is a term called activition record. Even if speaking to implementation, the choice of call stack or register should be decided by calling convention. No matter call stack or register, it will not invoke oeprator new function.