Thread: memcpy question

  1. #1
    Registered User
    Join Date
    Aug 2009

    memcpy question

    Say we have 2 arrays of size ten, the second array as 6 ints in it.
    If i do a memcpy(array1, array2 10);
    Will i get rubbish in the after the 6 spot in the array1 or will memcpy set them to null;

    ie what be the valueof array1[7] - [9]

    Is memset more safer before the memcpy on the array?
    Last edited by newbie30; 12-09-2009 at 06:29 AM.

  2. #2
    Join Date
    Oct 2007
    Inside my computer
    memcpy will only copy memory from one place to another. It will not in any way manipulate anything by setting it to 0 or null. So the answer to that question is: if there is rubbish in the array you copy, then yes, the destination will have it too.

    The second questions depends on what you use it for. For example, do you somehow depend on some elements that are not in use being 0? If so, then yes. Otherwise, it's probably a no.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Jan 2009
    Quote Originally Posted by newbie30 View Post
    Say we have 2 arrays of size ten, the second array as 6 ints in it.
    If i do a memcpy(array1, array2 10);
    That wont work, the size parameter is number of bytes. If your array consists of ints, 10 bytes wont cover the whole array.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SDL buffer channels question
    By TriKri in forum Game Programming
    Replies: 3
    Last Post: 12-09-2009, 05:52 PM
  2. Newbie question, C #
    By mate222 in forum C# Programming
    Replies: 4
    Last Post: 12-01-2009, 06:24 AM
  3. Question...
    By TechWins in forum A Brief History of
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  4. Trying to copy buffers using memcpy in C under UNIX
    By Meeper in forum C Programming
    Replies: 3
    Last Post: 07-26-2003, 08:51 AM
  5. memcpy
    By doubleanti in forum C++ Programming
    Replies: 10
    Last Post: 02-28-2002, 04:44 PM