malloc and new

Discussion in 'C++' started by Mohsen, Nov 9, 2006.

  1. Mohsen

    Mohsen Guest

    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
    Mohsen, Nov 9, 2006
    #1
    1. Advertising

  2. "Mohsen" <> wrote in message
    news:...
    : 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
    Ivan Vecerina, Nov 9, 2006
    #2
    1. Advertising

  3. Mohsen

    missdeer Guest

    Some library will overload operator new, then the great differences exist.

    "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
    >
    missdeer, Nov 9, 2006
    #3
  4. Mohsen

    Jim Langston Guest

    "Mohsen" <> wrote in message
    news:...
    > 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).
    Jim Langston, Nov 9, 2006
    #4
  5. Mohsen

    Ron Natalie Guest

    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.
    Ron Natalie, Nov 9, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John
    Replies:
    13
    Views:
    681
  2. ravi
    Replies:
    0
    Views:
    434
  3. Peter
    Replies:
    34
    Views:
    1,891
    Richard Tobin
    Oct 22, 2004
  4. porting non-malloc code to malloc

    , Feb 18, 2005, in forum: C Programming
    Replies:
    3
    Views:
    458
    Walter Roberson
    Feb 19, 2005
  5. Johs32

    to malloc or not to malloc??

    Johs32, Mar 30, 2006, in forum: C Programming
    Replies:
    4
    Views:
    309
    Captain Winston
    Mar 30, 2006
Loading...

Share This Page