memcpy和memmove函数的比较
来源:互联网 发布:gitlab ci php 编辑:程序博客网 时间:2024/06/05 04:19
代码:
;***
;memcpy.asm - contains memcpy and memmove routines
;
; Copyright (c) 1986-1997, Microsoft Corporation. All right reserved.
;
;Purpose:
; memcpy() copies a source memory buffer to a destination buffer.
; Overlapping buffers are not treated specially, so propogation may occur.
; memmove() copies a source memory buffer to a destination buffer.
; Overlapping buffers are treated specially, to avoid propogation.
;
;*******************************************************************************
;***
;memcpy - Copy source buffer to destination buffer
;
;Purpose:
; memcpy() copies a source memory buffer to a destination memory buffer.
; This routine does NOT recognize overlapping buffers, and thus can lead
; to propogation.
; For cases where propogation must be avoided, memmove() must be used.
;
; Algorithm:
void* memcpy(void* dest, void* source, size_t count)
{
void* ret = dest;
//copy from lower address to higher address
while (count--)
*dest++ = *source;
return ret;
}
memmove
memmove - Copy source buffer to destination buffer
;
;Purpose:
; memmove() copies a source memory buffer to a destination memory buffer.
; This routine recognize overlapping buffers to avoid propogation.
; For cases where propogation is not a problem, memcpy() can be used.
;
; Algorithm:
void* memmove(void* dest, void* source, size_t count)
{
void* ret = dest;
if (dest <= source || dest >= (source + count))
{
//Non-Overlapping Buffers
//copy from lower addresses to higher addresses
while (count --)
*dest++ = *source++;
}
else
{
//Overlapping Buffers
//copy from higher addresses lower addresses
dest += count - 1;
source += count - 1;
while (count--)
*dest-- = *source--;
}
return ret;
}
另一种实现:
void* mymemcpy( void* dest, const void* src, size_t count )
{
char* d = (char*)dest;
const char* s = (const char*)src;
// int n = (count + 7) / 8; // count > 0 assumed
int n = count >> 3;
switch( count & 7 )
{
do { *d++ = *s++;
case 7: *d++ = *s++;
case 6: *d++ = *s++;
case 5: *d++ = *s++;
case 4: *d++ = *s++;
case 3: *d++ = *s++;
case 2: *d++ = *s++;
case 1: *d++ = *s++;
case 0 } //while (--n > 0);
while (n-- > 0)
}
return dest;
}
- memcpy和memmove函数的比较
- memcpy和memmove函数的比较
- memcpy和memmove函数的比较与实现
- memcpy和memmove函数的比较与实现
- memcpy和memmove函数的比较与实现
- memcpy和memmove函数的比较与实现
- memcpy 和 memmove 函数
- memmove和memcpy函数
- memcpy函数和memmove函数的区别
- memcpy和memmove函数的实现
- memcpy和memmove函数的实现
- memcpy()和memmove() 函数的介绍
- memcpy和memmove的函数内部实现
- memcpy 与memmove的比较
- 实现memcpy和memmove函数
- 实现memcpy( )和memmove( )函数
- 实现memcpy和memmove函数
- memcpy,memmove函数的实现
- 使用开源CRM进行客户管理
- Wndows平台:wxWidgets-2.8.9 + codeblocks-8.02mingw
- 边学边用javascript(读书笔记)
- Reading Data with the SqlDataReader
- 嗅到了毕业的味道
- memcpy和memmove函数的比较
- CArray 详解
- 一个好用的hibernate泛型dao
- PowerBuilder中1个Application建立多个PBL
- 使用开源CRM进行客户关系管理(2)
- 10个你闻所未闻的奇趣网站
- JavaScript 技巧与高级特性
- 棱角分明: Google Reader 阅读器外观和功能更新
- 如何在intel安装mac操作系统