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

malloc and new

P: n/a
Dear All,
Do you know if there is any difference between 'new' and
'malloc' in terms of handling memory?
If someone has insufficient memory to run a big problem, do you think
it makes any difference to use 'new' or 'malloc'?
Thanks,
Mohsen

Nov 9 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"Mohsen" <ja*******@gmail.comwrote in message
news:11*********************@h54g2000cwb.googlegro ups.com...
: Dear All,
: Do you know if there is any difference between 'new' and
: 'malloc' in terms of handling memory?
It depends on the platform. But many implementations of
'new' just use malloc internally.

: If someone has insufficient memory to run a big problem, do you think
: it makes any difference to use 'new' or 'malloc'?
No (except for rare cases where you may benefit from 'realloc',
which is only available with the latter).
Can you tell more about the problem you are trying to solve?
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form

Nov 9 '06 #2

P: n/a
Some library will overload operator new, then the great differences exist.

"Mohsen" <ja*******@gmail.com>
??????:11*********************@h54g2000cwb.googleg roups.com...
Dear All,
Do you know if there is any difference between 'new' and
'malloc' in terms of handling memory?
If someone has insufficient memory to run a big problem, do you think
it makes any difference to use 'new' or 'malloc'?
Thanks,
Mohsen

Nov 9 '06 #3

P: n/a
"Mohsen" <ja*******@gmail.comwrote in message
news:11*********************@h54g2000cwb.googlegro ups.com...
Dear All,
Do you know if there is any difference between 'new' and
'malloc' in terms of handling memory?
If someone has insufficient memory to run a big problem, do you think
it makes any difference to use 'new' or 'malloc'?
Thanks,
Mohsen
Typically, it wouldn't matter, as most default implementations of new use
malloc under the seams. However, you are free to create your own
implementation of new, in which case it could make a diffeence depending on
what you did (I could forsee someone using memory sticks).
Nov 9 '06 #4

P: n/a
Mohsen wrote:
Dear All,
Do you know if there is any difference between 'new' and
'malloc' in terms of handling memory?
If someone has insufficient memory to run a big problem, do you think
it makes any difference to use 'new' or 'malloc'?
Thanks,
Mohsen
new crates objects.
malloc allocates bytes of memory.

New has a return type of something other than void*.
New can have the memory allocator swapped out (operator new overloaded)
New performs initialization of most types.
New performs "behind-the-scenes" types of initialization like
setting up run-time typing.
Nov 9 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.