我们一般new一个对象,申请内存的过程是operator new完成的,那么stl中的allocator是如何接管operator new完成内存申请的工作呢?对象的内存申请权是如何转移的?我看stl里面也没有重载operator new呀,另外如果在栈上生成我们的stl对象,也会经过allocator吗?
我们一般new一个对象,申请内存的过程是operator new完成的,那么stl中的allocator是如何接管operator new完成内存申请的工作呢?对象的内存申请权是如何转移的?我看stl里面也没有重载operator new呀,另外如果在栈上生成我们的stl对象,也会经过allocator吗?
6 回答6.8k 阅读✓ 已解决
3 回答2k 阅读✓ 已解决
2 回答3.9k 阅读✓ 已解决
2 回答3.2k 阅读✓ 已解决
1 回答3.2k 阅读✓ 已解决
1 回答4.4k 阅读✓ 已解决
1 回答2.7k 阅读✓ 已解决
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.