Claudio said:
You seriously need to hit the books again. Comments like these will make you
lose any credibility you may have had in this newsgroup.
You are absolutely right, I do need to continue studying C++ and programming
topics in general -- I'll *never* get to the point that I can say that I'm
done.
Aside from that, credibility in this forum has little to no value w/ me, so
I'll continue to make comments as I see them, be they right or wrong. I have
no problem being wrong, often am, and learn from each and every thread that I'm
involved in.
My statements reflect my treatment of the disparate allocation schemes.
Perhaps I should have phrased it as "I get in less trouble if I consider new as
an allocator of objects, and malloc as an allocator of raw memory".
Personally, I have very little use for malloc, and as you point out, typically
use it for legacy systems or where/when I'm interfacing w/ the operating system
where raw memory is required. I realize that new char[n] allocates memory, and
that no constructor is called for POD types, but I just find it more confusing
to have separate behaviors for new depending on whether or not the allocation
is for a POD type or a non-POD type. I feel sorry for new learners that have
to learn about the different allocation schemes, as well as learn about the
differences between the special class types.
I would have contemplated adding the following to the C++ language to
accommodate the allocation of (uninitialized) raw blocks of memory:
void * p = new void[size_in_bytes];
Then it would be possible to make the very real distinction between memory and
instance allocation.
C++ simply requires that you phrase it differently:
Right -- but it isn't at all clear what is really intended -- is it intended
that you are allocating space for a block of characters -- or -- are you
allocating a block of raw memory for some (non-char) specific purpose? Using
new char[], you can't determine that w/o careful examination of the context and
comments.
If there were a new void[] construct, it would be be infinitely more clear.
Leave new char[] for allocating space for characters, new void[] for allocating
raw memory. Best part is that there are no *new* keywords, the requirement for
casting the new char[] is eliminated, etc.
void * p = new char[size_in_bytes];
If you honestly believe that 'p' doesn't point to memory after this operation,
it's hopeless.
Of course I *know* that p points to allocated memory, but conceptually (for me)
it is more than just raw bytes, it is allocated space for characters. Using it
for something else (such as raw memory) just seems to break the special
distinction that new implies for allocation.