FAST method to copy char array?

This is a discussion on FAST method to copy char array? within the C++ Programming forums, part of the General Programming Boards category; Hi, I'm currently using a for loop to copy an unsigned char array of over 61,000 elements to another array. ...

  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    28

    FAST method to copy char array?

    Hi, I'm currently using a for loop to copy an unsigned char array of over 61,000 elements to another array. I was wondering if there was a method or an ASM function I can use to make this faster?

    Thanks

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    memcpy

  3. #3
    Counter-Strike Master
    Join Date
    Dec 2002
    Posts
    38
    use memcpy(). it takes a destination pointer, a source pointer, and the number of bytes you want to copy. you need to include <memory.h> in order to use it. it returns the value of the destination pointer, and it claims that there is "undefined behavior if the source and destination overlap". make sure that the destination is as big as or bigger than the source to avoid buffer overruns.

    http://msdn.microsoft.com/library/de...crt_memcpy.asp
    You say "Impressive!", but I already know it
    I'm a hardcore player and I'm not afraid to show it

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,500
    Find a better solution to your problem which doesn't involve any copying at all.

    > you need to include <memory.h> in order to use it
    memcpy() is in string.h - memory.h is a non-standard (probably archaic) header file.
    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.

  5. #5
    Registered User
    Join Date
    May 2005
    Posts
    28
    I cant think of any way to not have to copy it. I have two files with hexadecimal data in it and the program loads it into an unsigned char* array at the beginning of the program. Then it goes through a loop of encrypting something, then resets (the data i loaded before gets jumbled in the hexadecimal loop) so i must copy the untouched data over again.

    But memcpy() slightly sped it up

    Before it was doing about 333 cycles per second on the encryption loop now its doing about 350 it seems.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sorting Linked Lists
    By DKING89 in forum C Programming
    Replies: 6
    Last Post: 04-09-2008, 07:36 AM
  2. Replies: 16
    Last Post: 10-29-2006, 04:04 AM
  3. newbie needs help with code
    By compudude86 in forum C Programming
    Replies: 6
    Last Post: 07-23-2006, 08:54 PM
  4. Type and nontype parameters w/overloading
    By Mr_LJ in forum C++ Programming
    Replies: 3
    Last Post: 01-02-2004, 12:01 AM
  5. help with array of char and char **
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 04-20-2002, 02:23 PM

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