malloc and new

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mohsen

    #1

    malloc and new

    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

  • Ivan Vecerina

    #2
    Re: malloc and new

    "Mohsen" <jafarikia@gmai l.comwrote in message
    news:1163083494 .948073.37380@h 54g2000cwb.goog legroups.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



    Comment

    • missdeer

      #3
      Re: malloc and new

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

      "Mohsen" <jafarikia@gmai l.com>
      ??????:11630834 94.948073.37380 @h54g2000cwb.go oglegroups.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
      >

      Comment

      • Jim Langston

        #4
        Re: malloc and new

        "Mohsen" <jafarikia@gmai l.comwrote in message
        news:1163083494 .948073.37380@h 54g2000cwb.goog legroups.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).


        Comment

        • Ron Natalie

          #5
          Re: malloc and new

          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.

          Comment

          Working...