3 ms·
Yes, you're correct that generally you would not be able to use realloc for reasons you mentioned (and also because of destructors) but for simple POD (triviall
by menaerus 2y ago
Yes, you're correct that generally you would not be able to use realloc for reasons you mentioned (and also because of destructors) but for simple POD (trivially-constructible) types I think it should be possible, no?
In that case, realloc will either
(1) grow the existing memory, perhaps default initialize it, and call it a day
(2) Or if growing the memory is not possible, (a) allocate a new region of memory, (b) memcpy the contents from the old block and (c) free the old block.
Perhaps I am missing something but I think those are all the guarantees that realloc is giving to you.