用于复制数组的memcpy [英] memcpy for copying arrays

查看:74
本文介绍了用于复制数组的memcpy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


关于我的问题std :: copy与指针复制与成员

复制,我对该功能有些怀疑memcpy,正如tom_usenet

在他的回复中使用的那样。


- 这是一个c ++标准库函数吗?也就是说,我能确定每个c ++标准库都有这个功能吗?或者有一个c ++

的替代品吗?


- 这个功能如何运作?


- 可以此函数用于复制例如数组整数,长双打,

....安全吗?


- 我对这个功能还有什么了解?


感谢您的回复。


问候,


Franky B.

解决方案

fr ********** *****@ua.ac.be 写道:

你好,

关于我的问题std :: copy与指针复制与成员
复制,我对函数memcpy有些怀疑,就像tom_usenet在回复中使用的那样。

- 这是一个c ++标准库函数吗?


它是。

也就是说,我能确定每个c ++标准库都有这个功能吗?


是。

或者有c ++替代品吗?


std :: copy。

- 这个功能如何运作?


实现定义。

- 此功能是否可用于复制例如整,长双,
......安全吗?


它可以用来安全地复制POD。

- 我对这个功能还有什么了解?



这是一个C库函数。


-

Attila又名WW


< blockquote> On Tue,2003年9月16日12:55:09 +0200, fr ** *************@ua.ac.be 写道:

你好,

关注我的问题关于std :: copy与指针复制与成员
复制,我对函数memcpy有些疑问,正如tom_usenet
在他的回复中使用的那样。

- 这是一个c ++标准库函数吗?也就是说,我能确定每个c ++标准库都有这个功能吗?或者有替代它的c ++



它是C和C ++的标准配置。 std :: memcpy位于< cstring>中标题。

它也作为:: memcpy出现在< string.h>中头。 std :: copy

可以被认为是另一种选择,但是memcpy仍然是C ++的一部分。

- 这个函数如何工作?


取决于实施。有时它是一个编译器内在的

,导致插入适当的内联汇编程序。有时它

只是一个在循环中复制字节的函数。有时它是在汇编程序中实现的

函数。

- 此函数是否可用于复制例如数组的数组。整,长双,
......安全吗?


您可以随身携带任何POD类型(包括内置插件)。

- 我还应该了解这个功能吗?




源和目标范围不能重叠。如果他们可能

重叠,请使用memmove(通常会慢一点)。


Tom


2003年9月16日星期二,tom_usenet写道:

它是C和C ++的标准。 std :: memcpy位于< cstring>中标题。
它也作为:: memcpy出现在< string.h>中。头。 std :: copy
可以被认为是另一种选择,但memcpy仍然是C ++的一部分。




你是什么意思仍然是C的一部分++" ;?并且在什么意义上是

std ::复制一个替代方案(考虑到我们之前的b
早期测试的结果,速度要慢得多)?

- 此功能如何工作?



取决于实施。有时它是一个编译器内在的
导致插入适当的内联汇编程序。有时它只是一个在循环中复制字节的函数。有时它是在汇编程序中实现的功能。




但它可以被认为是最佳的可用功能来复制

数组?

- 此函数是否可用于复制例如数组int,long double,
...安全吗?



你可以用它复制任何POD类型(包括内置插件)。




这是怎么做到的?例如。如何复制双打数组?

- 我还应该了解这个函数吗?


源和目标范围不能重叠。如果它们可能重叠,请使用memmove(通常会慢一些)。




我认为std :: copy使用memmove(至少在gcc中) / libstdc ++),但它不是很好,但是很多......但是很多......


问候,


Franky B.


Hello,

following my question on "std::copy versus pointer copy versus member
copy", I had some doubts on the function memcpy, as was used by tom_usenet
in his reply.

- Is this a c++ standard library function? That is, can I be sure that
every c++ standard library has this function? Or is there a c++
alternative to it?

- How does this function work?

- Can this function be used to copy arrays of e.g. ints, long doubles,
.... safely?

- What else should I know about this function?

Thanks for any reply.

Regards,

Franky B.

解决方案

fr***************@ua.ac.be wrote:

Hello,

following my question on "std::copy versus pointer copy versus member
copy", I had some doubts on the function memcpy, as was used by
tom_usenet in his reply.

- Is this a c++ standard library function?
It is.
That is, can I be sure
that every c++ standard library has this function?
Yes.
Or is there a c++ alternative to it?
std::copy.
- How does this function work?
Implementation defined.
- Can this function be used to copy arrays of e.g. ints, long doubles,
... safely?
It can be used to copy PODs safely.
- What else should I know about this function?



It is a C library function.

--
Attila aka WW


On Tue, 16 Sep 2003 12:55:09 +0200, fr***************@ua.ac.be wrote:

Hello,

following my question on "std::copy versus pointer copy versus member
copy", I had some doubts on the function memcpy, as was used by tom_usenet
in his reply.

- Is this a c++ standard library function? That is, can I be sure that
every c++ standard library has this function? Or is there a c++
alternative to it?
It is standard in C and C++. std::memcpy is in the <cstring> header.
It is also present as ::memcpy, in the <string.h> header. std::copy
could be considered an alternative, but memcpy is still part of C++.
- How does this function work?
Depends on the implementation. Sometimes it is a compiler intrinsic
that causes appropriate inline assembler to be inserted. Sometimes it
is just a function that copies bytes in a loop. Sometimes it is a
function implemented in assembler.
- Can this function be used to copy arrays of e.g. ints, long doubles,
... safely?
You can copy any POD types with it (including built ins).
- What else should I know about this function?



The source and destination ranges cannot overlap. If they might
overlap, use memmove instead (which is usually a bit slower).

Tom


On Tue, 16 Sep 2003, tom_usenet wrote:

It is standard in C and C++. std::memcpy is in the <cstring> header.
It is also present as ::memcpy, in the <string.h> header. std::copy
could be considered an alternative, but memcpy is still part of C++.



What do you mean by "is still part of C++"? And in what sense is
std::copy an alternative (being so much slower, given the results of our
earlier tests)?

- How does this function work?



Depends on the implementation. Sometimes it is a compiler intrinsic
that causes appropriate inline assembler to be inserted. Sometimes it
is just a function that copies bytes in a loop. Sometimes it is a
function implemented in assembler.



But it can be considered as the most optimal available function to copy
arrays?

- Can this function be used to copy arrays of e.g. ints, long doubles,
... safely?



You can copy any POD types with it (including built ins).



And how is this done? E.g. how do I copy an array of doubles?

- What else should I know about this function?



The source and destination ranges cannot overlap. If they might
overlap, use memmove instead (which is usually a bit slower).



I think std::copy uses memmove (at least in gcc/libstdc++), but it is not
a bit slower, but a lot ...

Regards,

Franky B.


这篇关于用于复制数组的memcpy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆