Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C++
memcpy for copying arrays
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="tom_usenet, post: 1459624"] It was part of the C standard, and, along with the rest of the C standard library (with minor changes), it became part of the C++ standard. And in what sense is std::copy is a type-safe alternative to the non-typesafe function, std::memcpy. In addition, std::copy works with overlapped source and destination ranges, whilst memcpy doesn't, so, really, I suppose std::copy is an alternative to std::memmove rather than memcpy. It should be, but it is a quality of implementation issue. It's up to your compiler vendor and how much time they've spent tweaking it. You might want to read this: [URL]http://www.cuj.com/documents/s=7990/cujcexp1910alexandr/alexandr.htm[/URL] double source[10] = {blah}; double dest[10]; std::memcpy(dest, source, 10 * sizeof *source); memcpy is a bit dangerous, since it can't handle overlapping ranges, and it isn't typesafe. memmove can handle overlapping ranges, and hence tends to be used by std::copy for copying POD types. My benchmarks had std::copy and std::memcpy very similar on GCC: copy : 1.11 memcpy : 1.093 A difference of a couple of percent isn't something you should worry about. Tom [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C++
memcpy for copying arrays
Top