各位来讨论一下memcpy和memmove有什么区别????
解决方案 »
- IE加载ACTIVEX控件,如果鼠标不移动到ActiveX控件处,控件不显示
- 请教:如何让CTabCtrl控件的某一分页绑定一个ClistCtrl列表????
- 关于 ClistCtrl 的一个问题
- DirectDraw画图
- CTreeCtrl如何转化为CTreeView
- 1.我想使用CoInitializeEx(),初始化com却提示,该函数没有定义,请问是少了什么头文件或别的?
- 怎样设置才能向ListCtrl的第二、三、四列插入数据?
- 已经获得一个进程的句柄,怎样确定该进程所分配的内存空间的基址?多谢!
- 初学遇到问题 望大家帮忙解决
- 取得桌面上最前面窗口原点坐标的API函数是什么?
- ASSERT(pState->m_hSocketWindow != NULL);?
- 两裤衩拉,散分~~~
void * dst,
const void * src,
size_t count
)
{
void * ret = dst;#if defined (_M_MRX000) || defined (_M_ALPHA) || defined (_M_PPC)
{
extern void RtlMoveMemory( void *, const void *, size_t count ); RtlMoveMemory( dst, src, count );
}
#else /* defined (_M_MRX000) || defined (_M_ALPHA) || defined (_M_PPC) */
/*
* copy from lower addresses to higher addresses
*/
while (count--) {
*(char *)dst = *(char *)src;
dst = (char *)dst + 1;
src = (char *)src + 1;
}
#endif /* defined (_M_MRX000) || defined (_M_ALPHA) || defined (_M_PPC) */ return(ret);
}void * __cdecl memmove (
void * dst,
const void * src,
size_t count
)
{
void * ret = dst;#if defined (_M_MRX000) || defined (_M_ALPHA) || defined (_M_PPC)
{
extern void RtlMoveMemory( void *, const void *, size_t count ); RtlMoveMemory( dst, src, count );
}
#else /* defined (_M_MRX000) || defined (_M_ALPHA) || defined (_M_PPC) */
if (dst <= src || (char *)dst >= ((char *)src + count)) {
/*
* Non-Overlapping Buffers
* copy from lower addresses to higher addresses
*/
while (count--) {
*(char *)dst = *(char *)src;
dst = (char *)dst + 1;
src = (char *)src + 1;
}
}
else {
/*
* Overlapping Buffers
* copy from higher addresses to lower addresses
*/
dst = (char *)dst + count - 1;
src = (char *)src + count - 1; while (count--) {
*(char *)dst = *(char *)src;
dst = (char *)dst - 1;
src = (char *)src - 1;
}
}
#endif /* defined (_M_MRX000) || defined (_M_ALPHA) || defined (_M_PPC) */ return(ret);
}The memcpy function copies count bytes of src to dest. If the source and destination overlap, this function does not ensure that the original source bytes in the overlapping region are copied before being overwritten. Use memmove to handle overlapping regions.
The memcpy function copies count bytes of src to dest. If the source and destination overlap, this function does not ensure that the original source bytes in the overlapping region are copied before being overwritten. Use memmove to handle overlapping regions.
如果源地址和目标地址有重叠的地方,memcpy并不提供相应的保护机制,而memmove会提供比较全面的保护工作。
另外,memcpy的运行速度要比memmove快。
这个函数会从数组from的开头处,复制size个字符,并从头写入数组to中。这个函数的参数from和to如果是有重迭的两个数组,那么就会出错。这种情况,请使用memmove函数来代替它。
Memcpy函数返回to的地址;
以下是一个使用memcpy复制一个数组中内容的例子:
struct foo *oldarray, *newarray;
int arraysize;
...
memcpy (new, old, arraysize * sizeof (struct foo)); 函数:void * memmove (void *to, const void *from, size_t size)
从from中拷贝size字节到to中,即使这两个内存块有重迭也不影响执行效果。