I have a question regarding the new/delete operator compared to alloc/free.
When dynamicly allocating memory for a char*, I normaly use calloc so all reserved bits are set to zero, so I don’t have to bother with nulltermination.
Does char *string = new char[20] only reserve 20 items with the size of a char or does it also sets all bits in that memoryarea to zero?
If not can memset be used on this memory to accomplish that?
And if memset or any other method of zeroing out the allocated memory is possibly, can the new operator be overloaded for the native char type to do this work on its own?
When you use:
the allocated array is not initialized. In order to default-initialize it, you have to use:
This is stated in C++03 §5.3.4/15:
As for your second question — yes, you can use
memsetto fill the memory with any values you want.