realloc函数,它将为使用new而不是realloc分配的内存工作 [英] realloc function that would work for memory allocated using new instead of realloc

查看:121
本文介绍了realloc函数,它将为使用new而不是realloc分配的内存工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有一个 realloc 函数可以允许我调整内存块的大小(它与一个自由功能配对)。然而,我试图做同样的一个c ++类与一些成员指针分配内存使用而不是 realloc 。在c ++中是否有与 realloc 相同的关键字,这将允许我在使用new / delete而不是malloc或realloc和free配对内存时实现相同的目标?

I'm aware that there is a realloc function that would allow me to resize the memory block (and it's paired with a free function). However, I'm trying to do the same to a c++ class with some member pointers allocated memory using new instead of realloc. Is there an equivalent keyword to realloc in c++ that would allow me to achieve the same goal when the memory is paired using new/delete rather than malloc or realloc and free?

提前感谢。

推荐答案

不,没有。坦率地说,如果你使用新的或新的[]。你的C ++代码可能没有很好的设计。看看使用 std :: vector 而不是新的[],并使用值而不是新的。

No, there isn't. And frankly, if you are using new or new[]. your C++ code is probably not well designed. Look at using std::vector instead of new[], and at using values instead of new.

这篇关于realloc函数,它将为使用new而不是realloc分配的内存工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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