I want a memory block that I can resize, so using the C library functions:
{
char *buf = reinterpret_cast<char*>(std::malloc(n));
⋮
std::realloc(buf,N);
⋮
std::free(buf);
}
How can I go about using smart pointer protection (against leaking buf) in the above snippet?
If I replace the first instruction with this:
uBuf = std::make_unique<char[]>(n); char *buf = uBuf.get();
Would that "free" me from worrying about the final free()?
Would the std::unique_ptr tolerate resizing its *raw protégé (no longer n bytes) and do the delete[] expected from it when leaving the scope ?
If not, how to do it?