In what cases should I use memcpy over standard operators in C++?

前端 未结 7 1649
梦毁少年i
梦毁少年i 2020-12-13 06:36

When can I get better performance using memcpy or how do I benefit from using it? For example:

float a[3]; float b[3];

is cod

7条回答
  •  轮回少年
    2020-12-13 06:58

    Use std::copy(). As the header file for g++ notes:

    This inline function will boil down to a call to @c memmove whenever possible.

    Probably, Visual Studio's is not much different. Go with the normal way, and optimize once you're aware of a bottle neck. In the case of a simple copy, the compiler is probably already optimizing for you.

提交回复
热议问题