由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - why do we still use dynamic allocation?
相关主题
内存分配问题vector< vector > > 怎么初始化?
a small question about c++ memory allocation请教boost::any compile错误。
一个 default constructor 的问题关于内存泄漏
请问delete的问题C++一个string的小问题
请教关于allocator member function 的问题回答C++的弱问题
一个C++ operator new的重载问题C++ Interview Question
effective C++里的memory pool 一问:[合集] C++的弱问题
Is the order of initialization a, b, c or c, b, a?请教一下,exception时,destructor一定会被调用么?
相关话题的讨论汇总
话题: vector话题: dynamic话题: do话题: allocation
进入Programming版参与讨论
1 (共1页)
f******y
发帖数: 2971
1
since there are containers like vector, we can allocate memories at run time
much easier and do not need
to worry about the memory leak. It seems to me the "new","alloc" operators
are no longer necessary in
C++. At least, the programmers do not need to handle them directly at all. But
why they are still there?
p***o
发帖数: 1252
2
vector is a library, new is a language feature, how can you
implement vector without new?
Anyway I agree with you that in many cases, new should not be
used directly nowadays.

time

【在 f******y 的大作中提到】
: since there are containers like vector, we can allocate memories at run time
: much easier and do not need
: to worry about the memory leak. It seems to me the "new","alloc" operators
: are no longer necessary in
: C++. At least, the programmers do not need to handle them directly at all. But
: why they are still there?

E*****7
发帖数: 128
3
For objects that use dynamic memory, new operation must be performed in the constructor to allocate the memory. An object used in containers such as vector must have a constructor either written by the programmer to initialize it or a default constructor generated by the compiler by default. If your program always deals built-in type such as integer in vector where the constructor of int generated by the compiler by default always does its job, you need not worry about dynamic allocation at
1 (共1页)
进入Programming版参与讨论
相关主题
请教一下,exception时,destructor一定会被调用么?请教关于allocator member function 的问题
在子函数内开内存,返回主函数指针然后释放空间是不是很糟糕的(转载)一个C++ operator new的重载问题
关于C/C++里的Static variable的memory allocation/initializaeffective C++里的memory pool 一问:
What does the default constructor do?Is the order of initialization a, b, c or c, b, a?
内存分配问题vector< vector > > 怎么初始化?
a small question about c++ memory allocation请教boost::any compile错误。
一个 default constructor 的问题关于内存泄漏
请问delete的问题C++一个string的小问题
相关话题的讨论汇总
话题: vector话题: dynamic话题: do话题: allocation