How to expand allocated memory in place
问题 Is there something like std::realloc but do nothing if it fails to expand the existing memory (of course it will let you know it failed)? I mean truly expand in place. Not copy to a newly created memory chunk. 回答1: Contrary to what other answers say, the function you need could be provided by the C standard ibrary. It isn't for some reason or other. It was considered for an adition to the C standard, see e.g. http://www.open-std.org/JTC1/SC22/wg14/www/docs/n1527.pdf (search for try_realloc).