普通对new的调用与由stl容器进行的调用之间有什么区别? [英] What is the diffference between normal call to new and one made by stl containers?

查看:72
本文介绍了普通对new的调用与由stl容器进行的调用之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

普通调用new和stl容器进行的调用之间有什么区别?首先有什么区别吗?

What is the diffference between normal call to new and one made by stl containers?is there any difference in the first place?

推荐答案

STL容器使用它们包含的类型的默认分配器.但是,您可以对此进行控制(这是容器构造函数的可选参数),例如,参见 std :: vector文档 [ ^ ].
STL containers use the default allocator of the type they contain. However you have control on this (is an optional argument of the container constructor), see, for instance std::vector documentation[^].


STL容器不调用new.不是在堆上分配对象时的方式.

只需看看 std :: allocator [本文 [
STL containers don''t call new. Not the way you do when allocating an object on the heap.

Just give a look to std::allocator[^]. This is what STL containers use to allocate dynamic memory.

This article[^] explain how it is implemented.


这篇关于普通对new的调用与由stl容器进行的调用之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆