Bryan Fok
Bryan Fok

Reputation: 3487

what is the different between memmove and c++11 std::move?

What is the different between memmove and c++11 std::move? Can I use std::move on overlapped memory location? And which method has the higher speed performance?

Upvotes: 4

Views: 2873

Answers (1)

Sneftel
Sneftel

Reputation: 41504

A few ways:

  1. std::move invokes assignment operators, while memmove does not. As such, memmove is not appropriate for non-POD types.
  2. std::move will work on any C++ container type, while memmove will only work on those which store elements linearly in contiguous memory locations (such as with arrays and std::vector).
  3. std::move is not appropriate for a destination range which overlaps the source range on the left (use move_backwards for that), while memmove is appropriate for all overlapping ranges.

In situations where you're copying POD types to a right-overlapping range, it is likely that memmove and std::move will have similar performance. In all other situations, only one of the two is appropriate, so you can't really compare performance.

Upvotes: 6

Related Questions