Is it safe to realloc memory allocated with new?

前端 未结 9 695
孤街浪徒
孤街浪徒 2020-12-02 17:12

From what is written here, new allocates in free store while malloc uses heap and the two terms often mean the same thing.

<
9条回答
  •  感动是毒
    2020-12-02 17:43

    Yes - if new actually called malloc in the first place (for example, this is how VC++ new works).

    No otherwise. do note that once you decide to reallocate the memory (because new called malloc), your code is compiler specific and not portable between compilers anymore.

    (I know this answer may upset many developers, but I answer depends on real facts, not just idiomaticy).

提交回复
热议问题