Comparing Memory Allocation Methods

J

John Harrison

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
 
B

Bill Seurer

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?

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,008
Latest member
HaroldDark

Latest Threads

Top