quick memcpy question

This is a discussion on quick memcpy question within the C Programming forums, part of the General Programming Boards category; I have an array and also a buffer of char* I have memcpy from buffer into the array, is this ...

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    58

    quick memcpy question

    I have an array and also a buffer of char*

    I have memcpy from buffer into the array, is this ok or should i memcpy into another buffer of char* and free it when done?

    I dont have to free an array after a memcpy as not technically a pointer.

  2. #2
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    No problem. The only thing you need to worry about is if your array is big enough to hold all the data you're copying.
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  3. #3
    Registered User
    Join Date
    Aug 2009
    Posts
    58
    Grand cheers for that, just couldnt remember if it was ok or not. Size is grand as all taken care of!

    Thanks

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,548
    The only thing to watch out for with memcpy() is to make sure that source and destination do NOT overlap.

    If they're two separate buffers, then it's not a problem.

    But if you're trying to move the tail of a buffer to the head (so you can add more data), then memcpy() is the wrong thing to use. Use memmove() in this case.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Very quick math question
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 10-26-2005, 11:05 PM
  2. very quick question.
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 07-24-2002, 03:48 AM
  3. quick question
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 07-22-2002, 04:44 AM
  4. Quick Question Regarding Pointers
    By charash in forum C++ Programming
    Replies: 4
    Last Post: 05-04-2002, 11:04 AM
  5. Quick question: exit();
    By Cheeze-It in forum C Programming
    Replies: 6
    Last Post: 08-15-2001, 05:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21