What is the most efficient way of copy an array of ints in objective C?
What is the most efficient way to copy an array of 1000 ints from one array to another in objective C?
This will be ru开发者_JAVA技巧nning on an iphone within some drawing code so its important to be as efficient as possible.
Thanks.
if the concern is efficiency, I'm assuming this is a C array of ints. If so, you can use memcpy().
For example:
int copyOfArr[4], arr[4] = {0,1,2,3};
memcpy(copyOfArr, arr, sizeof(arr));
Hope that helps.
If you are talking about a normal C array, then memcpy is the most efficient way. If you are talking about NSArray, then send a "copy" message.
精彩评论