Re: Did realloc move object?

Discussion in 'C Programming' started by Kevin Easton, Aug 4, 2003.

  1. Kevin Easton

    Kevin Easton Guest

    Ian Pilcher <> wrote:
    > Just to confirm, there does not seem to be a completely portable way to
    > determine whether realloc has moved an object (since C99's intptr_t and
    > uintptr_t are optional).


    Use memcmp to compare the bytes making up the old pointer with the bytes
    making up the new one. This has a small chance of false positives (say,
    on systems where pointers have padding - OK, a *very* small chance), and
    no false negatives, so it seems appropriate for your use. On usual systems
    it will have neither.

    - Kevin.
     
    Kevin Easton, Aug 4, 2003
    #1
    1. Advertising

  2. Kevin Easton

    Ian Pilcher Guest

    Kevin Easton wrote:
    > Use memcmp to compare the bytes making up the old pointer with the bytes
    > making up the new one. This has a small chance of false positives (say,
    > on systems where pointers have padding - OK, a *very* small chance), and
    > no false negatives, so it seems appropriate for your use. On usual systems
    > it will have neither.


    One might argue that on a "usual" system I could just compare the old
    pointer to the new pointer and be on my way.

    But you make a good point. As long as the result of a false positive is
    only a performance hit, memcmp will do.

    --
    ========================================================================
    Ian Pilcher
    ========================================================================
     
    Ian Pilcher, Aug 4, 2003
    #2
    1. Advertising

  3. On Mon, 4 Aug 2003, Kevin Easton wrote:
    >
    > Ian Pilcher <> wrote:
    > > Just to confirm, there does not seem to be a completely portable way to
    > > determine whether realloc has moved an object (since C99's intptr_t and
    > > uintptr_t are optional).

    >
    > Use memcmp to compare the bytes making up the old pointer with the bytes
    > making up the new one. This has a small chance of false positives (say,
    > on systems where pointers have padding - OK, a *very* small chance),


    And on systems where one pointer value can have several different
    representations - like Intel x86. Make that a slightly larger chance. :)

    > and no false negatives, so it seems appropriate for your use. On
    > usual systems it will have neither.


    Probably still true; I think "most" x86 compilers pick a "reduced form"
    for segment-offset pointers, so that they're all stored in the same
    way and bit-by-bit comparisons work as expected.

    -Arthur
     
    Arthur J. O'Dwyer, Aug 4, 2003
    #3
    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. Russell Hanneken

    Re: Did realloc move object?

    Russell Hanneken, Aug 3, 2003, in forum: C Programming
    Replies:
    29
    Views:
    717
    Dan Pop
    Aug 7, 2003
  2. Francois Grieu

    Does realloc "move" a block it shortens?

    Francois Grieu, Sep 10, 2004, in forum: C Programming
    Replies:
    8
    Views:
    411
    Barry Schwarz
    Sep 15, 2004
  3. Eduardo78
    Replies:
    0
    Views:
    278
    Eduardo78
    Nov 3, 2005
  4. Andrew Tomazos
    Replies:
    2
    Views:
    699
    Nobody
    Dec 12, 2011
  5. Daniel Waite
    Replies:
    2
    Views:
    247
    Daniel Waite
    May 2, 2008
Loading...

Share This Page