Thread: reallocation

  1. #1
    Registered User
    Join Date
    Jun 2007
    Posts
    99

    reallocation

    When reallocating memory, if any other pointer points to same piece of memory, do I have to readjust these other pointers or do they get readjusted automatically?

  2. #2
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    No, they'll still point to the start of the block of memory, ie you don't have to touch them. http://www.opengroup.org/onlinepubs/...h/realloc.html

    Quote Originally Posted by http://www.opengroup.org/onlinepubs/007908775/xsh/realloc.html
    If ptr does not match a pointer returned earlier by calloc(), malloc() or realloc() or if the space has previously been deallocated by a call to free() or realloc(), the behaviour is undefined.
    Last edited by zacs7; 06-17-2007 at 04:36 AM.

  3. #3
    Registered User
    Join Date
    Jun 2007
    Posts
    99
    Please clarify, i m in doubt

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    You will have to readjust ALL the pointers following realloc, since realloc can actually move the memory to somewhere else.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 07:25 PM
  2. reallocation
    By George2 in forum C++ Programming
    Replies: 11
    Last Post: 03-06-2008, 08:13 PM
  3. Memory reallocation in C++
    By spank in forum C++ Programming
    Replies: 2
    Last Post: 08-08-2007, 09:56 AM
  4. Can reducing a vector's size cause a reallocation?
    By robatino in forum C++ Programming
    Replies: 19
    Last Post: 04-12-2007, 12:13 PM
  5. dynamic reallocation
    By ichijoji in forum Game Programming
    Replies: 4
    Last Post: 05-06-2004, 09:35 AM