Jump to content
  • Advertisement

Archived

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

John D

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

This topic is 5584 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
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
#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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!