reallocate extra memory

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

    reallocate extra memory

    Hi everyone,

    I had allocated from memory for a character array using the new
    operator in cpp. Now i want to increase this allocation dynamically,
    realloc() works with memory allocated by malloc(), does it work with
    memory allocated by new? If not, is there any operator that can do the
    same in c plus plus?

    Thanks in advance ! ! !
  • Gianni Mariani

    #2
    Re: reallocate extra memory

    Rahul wrote:
    Hi everyone,
    >
    I had allocated from memory for a character array using the new
    operator in cpp. Now i want to increase this allocation dynamically,
    realloc() works with memory allocated by malloc(), does it work with
    memory allocated by new? If not, is there any operator that can do the
    same in c plus plus?
    No. The only thing you can ho with objects allocated with new is to
    allocate a larger chunk and copy the original chunk's content.

    Comment

    • Kai-Uwe Bux

      #3
      Re: reallocate extra memory

      Rahul wrote:
      I had allocated from memory for a character array using the new
      operator in cpp. Now i want to increase this allocation dynamically,
      realloc() works with memory allocated by malloc(), does it work with
      memory allocated by new? If not, is there any operator that can do the
      same in c plus plus?
      No, but you can use std::vector<cha rinstead of a raw pointer.


      Best

      Kai-Uwe Bux

      Comment

      Working...