realloc in case of new and delete operators

Discussion in 'C++' started by free2cric, Apr 5, 2005.

  1. free2cric

    free2cric Guest

    Hi, As you know memory block assigned by malloc can be resized by
    realloc with previously assigned data in the memory block intact. How
    this to achieve in case
    if the memory block is assigned with "new" operator.
    thanks crick.
    free2cric, Apr 5, 2005
    #1
    1. Advertising

  2. free2cric wrote:
    >
    > Hi, As you know memory block assigned by malloc can be resized by
    > realloc with previously assigned data in the memory block intact. How
    > this to achieve in case
    > if the memory block is assigned with "new" operator.


    There is no way to do that with one simple call.

    Allocate more memory
    copy the old content to the new location
    free the old memory

    Or simply use a standard contained such as std::vector.
    They do all of this automatically for you under the hood.

    --
    Karl Heinz Buchegger
    Karl Heinz Buchegger, Apr 5, 2005
    #2
    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. HeroOfSpielburg
    Replies:
    1
    Views:
    388
    Alf P. Steinbach
    Aug 6, 2003
  2. Nimmi Srivastav

    Overloading new and delete operators

    Nimmi Srivastav, Jan 31, 2004, in forum: C++
    Replies:
    3
    Views:
    2,676
    John Harrison
    Feb 2, 2004
  3. GianGuz
    Replies:
    4
    Views:
    376
    Jonathan Mcdougall
    Dec 20, 2004
  4. Jef Driesen
    Replies:
    1
    Views:
    501
    Gernot Frisch
    Jan 19, 2005
  5. Douglas Peterson
    Replies:
    1
    Views:
    2,764
    Larry Brasfield
    Jan 22, 2005
Loading...

Share This Page