   quick data copying (c/c++)
  Is there a way (in c/c++) to copy arrays and pointers without using loops? Somwthing like:int a[1000];int b[1000] = {1,2,3...};a = b;I want the outcome to fill every variable in the array with the values of another array...instead of this:int a[1000];int b[1000] = {1,2,3...};for(int r = 0; r < 1000; r++) a[r] = b[r];The reason is I want to make a macro that can reinitialize a variable so i can use dynamic array casting.   "Solutions are not the answer." - Richard Nixon 
  keep track of the array length, and then memcpy() from one to the other? That''s how I do it.. Klowner________________http://dugnet.com/klown ;  Prefer std::copy over memcpy. ;  For shallow copy, use the above suggestions. For deep copy, you have to loop through and set each individual element like your original post does.The difference between shallow and deep copy, if you don''t know, can be illustrated like this:Let''s say you have an image stored in a structure like this:struct Image{    int Width;    int Height;    char* Data;};And say you want to copy it. A shallow copy would copy the width, height, and pointer to the new image, meaning the Data pointer would point to the same location in memory as the original image. So changing something in the original would also change the copy, and if you try deleting one without the other knowing then you''ll run into memory errors.A deep copy would copy the width and height but also create a new array and copy the contents of the old array onto the new one. You''d need to do that yourself, like with an overloaded "=" operator.Anyway for anything not a pointer, shallow copy is all you need. That''s this://given int* Copy, int* Original:memcpy( Copy, Original, NumElements * sizeof(int) );   ~CGameProgrammer( ); -- Post screenshots of your projects. There''s already 134 screenshot posts.    ;quote:Original post by antareus  Prefer std::copy over memcpy.   What exactly is the major difference between std::copy and memcpy? If I want to copy an array of say four-thousand bytes, what can std::copy do that memcpy can''t?;  It can be type safe and it can cope with non-PODs.;  Oh, right. But memcpy is okay to use if I'm just copying integers, doubles, etc, right?P.S. Never mind, just saw the other thread about memcpy vs std::copy.   [edited by - Red Ant on February 16, 2004 10:29:13 AM]