malloc and new

M

Mohsen

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
 
I

Ivan Vecerina

: 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?
 
J

Jim Langston

Mohsen said:
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).
 
R

Ron Natalie

Mohsen said:
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.
 

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,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top