什么是C ++中realloc的最佳替代方案 [英] What is the best alternative for realloc in C++
问题描述
有人可以告诉我C ++中realloc的最佳选择是什么?
使用new运算符realloc分配内存是否安全? ?
Kumar写道:
有人可以告诉我什么是在C ++中realloc的最佳替代方案?
您需要什么?
重新分配使用新运算符分配的内存是否安全?
不能。你只能在从malloc或
realloc获得的内存上使用realloc。此外,realloc无法正常使用非pod对象,因为
它并不关心构造函数和析构函数。
>
Kumar写道:
有人可以告诉我什么是C ++中realloc的最佳选择?
您需要什么?
重新分配使用新运算符分配的内存是否安全?
不能。你只能在从malloc或
realloc获得的内存上使用realloc。此外,realloc无法正常使用非pod对象,因为
它并不关心构造函数和析构函数。
>
2004年4月6日02:12:33 -0700 comp.lang.c ++, rs ****** @ acmet.com
(Kumar)写道,
有人可以告诉我什么是C ++中realloc的最佳选择?
std :: vector<> :: resize()
重新分配使用new运算符分配的内存是否安全?
不要使用''new''。
Hi,
Can somebody advise me on what is the best alternative for realloc in C++?
Is it safe to "realloc"ate memory allocated using new operator ?
Kumar wrote:
Hi,
Can somebody advise me on what is the best alternative for realloc in
C++?
What would you need it for?
Is it safe to "realloc"ate memory allocated using new operator ?
No. You can only use realloc on memory that you got from malloc or
realloc. Also, realloc won''t work properly with non-pod objects, since
it doesn''t care about constructors and destructors.
Kumar wrote:
Hi,
Can somebody advise me on what is the best alternative for realloc in
C++?
What would you need it for?
Is it safe to "realloc"ate memory allocated using new operator ?
No. You can only use realloc on memory that you got from malloc or
realloc. Also, realloc won''t work properly with non-pod objects, since
it doesn''t care about constructors and destructors.
On 6 Apr 2004 02:12:33 -0700 in comp.lang.c++, rs******@acmet.com
(Kumar) wrote,Hi,
Can somebody advise me on what is the best alternative for realloc in C++?
std::vector<>::resize()
Is it safe to "realloc"ate memory allocated using new operator ?
Don''t use ''new''.
这篇关于什么是C ++中realloc的最佳替代方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!