|
-
February 3rd, 2009, 11:37 AM
#1
std::memcpy
Is it in poor taste to use std::memcpy in a highly-OO C++ application? That is, in the same way that the use of realloc / free / malloc / calloc is frowned upon?
-
February 3rd, 2009, 11:44 AM
#2
Re: std::memcpy
That's a loaded question. memcpy can only be used on POD types. If you know the data that you want to copy is of POD type then you can use memcpy, if not then don't as it will constitute undefined behaviour.
As an aside, under some circumstances, a compiler may convert a "copy by iteration" into a memcpy if it can figure out that the data held in both source and destination is both contiguous and POD.
-
February 3rd, 2009, 11:54 AM
#3
Re: std::memcpy
There's not much reason to prefer memcpy over std::copy in C++, and the latter handles a larger number of cases correctly.
-
February 3rd, 2009, 11:58 AM
#4
Re: std::memcpy
Agreed, and, the compiler can make it just as fast for POD types.
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
|