|
-
August 10th, 2010, 09:35 AM
#15
Re: Unitialized memory help
 Originally Posted by ninja9578
Why not:
Code:
memmove(&arr2[0], &arr[0], 5 * sizeof(int));
Well, for one thing, memcpy() is always at least as efficient as memmove(), and sometimes moreso. Furthermore, while both of those would be perfectly fine on ints, they would not generalize to any type; for instance, it could cause a crash if you tried it with an array of std::string.
So the "proper" solution if you didn't want to use a loop would be
Code:
std::copy(arr,arr+5,arr2);
This would of course decay to memcpy() internally when instantiated for ints.
Of course, that disregards move semantics. I'm not sure if there's a multi-element form of std::move on any compilers yet, or even if that's going to be the name for that function when there is.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|