Regrow memory allocated by operator new()?

后端 未结 4 1691
心在旅途
心在旅途 2021-01-22 03:59

Is it possible to regrow memory allocated by operator new(), when allocated this way:

char* buf = new char[60];

The C++ FAQ states

4条回答
  •  一整个雨季
    2021-01-22 04:53

    The correct way is to not do it.

    Simply allocate new memory if the previous allocation wasn't big enough.

    Or use std::vector which wraps all this functionality very efficiently.

提交回复
热议问题