Archived

This topic is now archived and is closed to further replies.

John D

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

Recommended Posts

John D    122
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]

Share this post


Link to post
Share on other sites
RapidStunna    122
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

Share this post


Link to post
Share on other sites
John D    122
#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 <;



Share this post


Link to post
Share on other sites