By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,260 Members | 1,386 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,260 IT Pros & Developers. It's quick & easy.

Comparing Memory Allocation Methods

P: n/a
Wei
http://msdn.microsoft.com/library/de...on_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?
Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"Wei" <wa******@21cn.com> wrote in message
news:d3**************************@posting.google.c om...
http://msdn.microsoft.com/library/de...on_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
Jul 22 '05 #2

P: n/a
Wei wrote:
http://msdn.microsoft.com/library/de...on_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?


If you use new or malloc your code might run somewhere other than on
Windows. The author is trying to get you to use the Windows specific
allocation functions. The disadvantage is to Microsoft, not you.
Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.