What is C++ version of realloc(), to allocate the new buffer and copy the contents from the old one?

后端 未结 4 1320
北恋
北恋 2020-12-06 10:04

In C we used malloc(), free(), but in C++ youare using new, delete, but in C we also have realloc, which will alloc the new block and

4条回答
  •  执笔经年
    2020-12-06 10:19

    realloc isn't used in C++ because C++ wants to use its copy and default constructors and destructors for things like this in general. But if you got plain old types that you want to handle as fast as possible, there is no reason not to roll your own array class that does what you want. I'm surprised there isn't one that's mostly STL-compatible already in the top Google page.

提交回复
热议问题