Sign in to follow this  

the fastest/best way to do this....

This topic is 4713 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

Hello, what is the fastest way to add an array of integers, to a current array of integers? (in C++) just for clarity... int arr1[500]; // temp array int arr2[1000]; // array i want to append values to // fill arr1 with values // fill arr2 with 500 values so // one way is to append arr2 with arr1 is...... for (int i = 0; i < 500; i++) arr2[500+i] = arr[i]; But is there a faster way???? Cheers Paul

Share this post


Link to post
Share on other sites
I think you're looking for memcpy:


int arr1[500]; // temp array
int arr2[1000]; // array i want to append values to

for(int count=0; count<500; ++count) { // Fill arrays with values
arr2[count] = count;
arr1[count] = count+500;
}

memcpy(&arr2[500], arr1, 500*sizeof(int));


You might want to test that though [grin]

Share this post


Link to post
Share on other sites
Quote:
Original post by The Rug
I think you're looking for memcpy

Eh yeah, that's what I meant too ;)
You could use CopyMemory, but is Windows specific, I believe.


[Edited by - WanMaster on January 18, 2005 9:54:03 AM]

Share this post


Link to post
Share on other sites

This topic is 4713 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this