Wei said:
http://msdn.microsoft.com/library/d.../base/comparing_memory_allocation_methods.asp
On the above MSDN site, it says The malloc function has the
disadvantage of being run-time dependent. The new operator has the
disadvantage of being compiler dependent and language dependent.
Can someone give examples to describe the disadvantage?
Can anyone explain what the f**k MS are talking about?
'language dependent' - I can only assume that means malloc is usable in C
and C++ whereas new is only usable in C++.
'compiler dependent' - perhaps that refers to the fact the VC++ 6 does not
implement the new operator correctly. Something most other compilers manage
to get right.
'runtime dependent' - perhaps this refers to the C runtime library code that
most VC++ programs link with. It's hardly a disadvantage, and it would apply
to new as well.
What is more the author of that page has completely ignored the fact that he
is not comparing like with like. new adds very significant functionality
that the other methods do not have (namely that it calls constructors and
throws exceptions).
I would just ignore this rubbish. In general C++ code you should use new,
anything else is for specialised use only, when you know exactly why you
need an alternative method of allocating memory.
john