[C++] how do you copy an Array?

Started by
3 comments, last by John D 21 years, 1 month ago
What's the best way to copy an array of varying sizes to a new area in memory for temperal use. &Data[var][var]; SizeOf(Data[var][var]); ??? copy starting point to ending point to new a address rename with pointer??? unsigned char *New_Data; Also //A pointer to array; *pArray; unsigned int pArray_size; ??? copy starting point to ending point to new a address rename with pointer??? [edited by - john D on March 6, 2003 12:24:38 PM]
Advertisement
I would ditch arrays and go with std::vectors
daerid@gmail.com
use the c lib function memcpy

-Lucas
-Lucas
memcpy is what you need. its very fast - uses assembly. altho pure aseembly is faster because no stack push/pop calls are needed. anyway, here''s an example:

int array1[100], array2[200];
memset(array1,7,sizeof(array1));
memset(array2,3,sizeof(array2));
//****
memcpy(array2,array1,sizeof(array1));

---
Brent Gunning | My Site
#include <string.h>
void *memcpy(void *s1, const void *s2, size_t n);
s1
Points to the target buffer.
s2
Points to the source buffer.
n
Is the number of bytes to copy.
The memcpy() function returns pointer s1.

thanks that will work <;



This topic is closed to new replies.

Advertisement