For example -
#include <memory>
int main(){
const auto bufSize = 1024;
auto buffer = std::make_unique<char[]>(bufSize);
}
Is the buffer here already filled with '\0'
characters or will I have to manually fill it to avoid garbage values.
And what would be the possible way to do this, will std::memset(&buffer.get(), 0, bufSize)
suffice?
All of the make_*
functions use value-initialization for the type if you don't provide constructor parameters. Since the array-form of make_unique
doesn't take any parameters, it will zero-out the elements.