#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2006
    Posts
    2
    Rep Power
    0

    Difference between memmove and memcpy


    Hi,

    When i was going through some book they have given an explanation about memmove and memcpy.

    MemCpy.

    It copies count characters from the array pointed from source to destination. If the array overlaps the behaviour of memcpy is undefined.

    Memmove

    It copies count characters from the array pointed from source to destination. If the array overlaps the copy will take place correctly.

    In the above explanation i am not able to understand what they mean by array overlaps. It will be nice if any one give some detail explanation for that.

    Regards,
    Gopal
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,376
    Rep Power
    1871
    Code:
    char foo[] = "hello world";
    memmove ( &foo[0], &foo[5], 10 );
    Basically, it's saying that &foo[0] + 10 bytes is past &foo[5]
    So part of what you're copying from will eventually get overwritten. It is vitally important then that you do the copying in the right order to avoid losing data.

    memmove guarantees that this will happen
    memcpy does not.

IMN logo majestic logo threadwatch logo seochat tools logo