Thread: Realloc Question

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    61

    Realloc Question

    given the followng code, am i right to say that pointer r and ptr will be the same if the location of the memory does change? r will only take a new position if it needs to shift to another part of the memory? thanks

    Code:
    void* realloc(void *ptr, size_t size) {
        static void* (*func)();
        void *r;
        if(!func) {
            func = (void *(*)())dlsym(RTLD_NEXT, "realloc");
        }
        r = func(ptr, size);
        printf("realloc %p %d %p\n", r, size, ptr);
        return r;
    }

  2. #2
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Your question is "Does something stay still if it doesn't move?" The answer is yes.

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    61
    ok so jus to confirm again. r and ptr will be the same if place in memory is not changed. r and ptr will be different if place in memory is changed. thanks

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    realloc also can return NULL... in this case also returned value will be different from the original one
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. another do while question
    By kbpsu in forum C++ Programming
    Replies: 3
    Last Post: 03-23-2009, 12:14 PM
  2. Realloc Quick Question.
    By killpoppop in forum C Programming
    Replies: 36
    Last Post: 01-13-2009, 01:04 PM
  3. Quick realloc question
    By Matt13 in forum C Programming
    Replies: 7
    Last Post: 04-02-2004, 08:40 AM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM