内存重叠拷贝函数
#include<stdio.h>
#include<assert.h>
voidmy_memmove(void*p1,voidconst*p2,size_tcount)
{
char*dest=(char*)p1;
char*src=(char*)p2;
assert(p1);
assert(p2);
if((dest>src)&&(dest<src+count))
{
while(count--)..
分类:
编程语言 时间:
2015-11-21 07:16:26
阅读次数:
153
题目:自己定义一个函数,实现my_memcpy和my_memmove函数。题目分析:memcpy函数主要实现的是内存的拷贝,函数接受任意类型的参数,并且有拷贝个数的限制,函数与strcpy函数在功能上有相似点,也有不同点。memmove函数在memcpy函数的基础上解决了内存重叠的问题。下面是memcpy..
分类:
其他好文 时间:
2015-11-20 23:16:41
阅读次数:
320
这里memcpy与memmove函数的模拟实现,需要用到空指针来传递参数,之后强制类型转换为char型,用size_t这个宏接受偏移量进行偏移,模拟实现如下:memcpy函数:void*my_memcpy(void*dst,constvoid*src,size_tcount)
{
assert(dst);
assert(src);
void*ret=dst;
while(count--)
{
..
分类:
编程语言 时间:
2015-11-19 07:16:11
阅读次数:
160
#define_CRT_SECURE_NO_WARNINGS1
#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
void*my_memmove(void*p1,void*p2,size_tcount)
{
assert(p1);
assert(p2);
char*dest=(char*)p1;
char*src=(char*)p2;
dest=dest+16;
src=src+8;
if((src<de..
分类:
编程语言 时间:
2015-11-19 07:15:14
阅读次数:
201
#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
void*my_memmove(void*p1,constvoid*p2,size_tcount)
{
assert(p1);
assert(p2);
char*dest=(char*)p1;
char*src=(char*)p2;
dest=dest+16;
src=src+8;
if((src<=dest)&&(dest<=(sr..
分类:
数据库 时间:
2015-11-19 07:14:42
阅读次数:
207
#define_CRT_SECURE_NO_WARNINGS1
#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
void*my_memmove(void*p1,void*p2,size_tcount)
{
assert(p1);
assert(p2);
char*dest=(char*)p1;
char*src=(char*)p2;
dest=dest+16;
src=src+8;
if((src<de..
分类:
编程语言 时间:
2015-11-19 07:14:32
阅读次数:
192
#include #include using namespace std;void* memmove(void *dst, const void *src, size_t count){ // 容错处理 if (dst == NULL || src == NULL){ return NULL; ....
分类:
其他好文 时间:
2015-10-24 08:57:25
阅读次数:
186
第一部分 综述memcpy、memmove、memset、memchr、memcmp都是C语言中的库函数,在头文件string.h中。memcpy和memmove的作用是拷贝一定长度的内存的内容,memset用于缓冲区的填充工作,memchr用于字符的查找工作,memcmp用于比较内存中缓冲区的大....
分类:
其他好文 时间:
2015-08-17 21:08:05
阅读次数:
259
memcpy与memmove的目的都是将N个字节的源内存地址的内容拷贝到目标内存地址中。但当源内存和目标内存存在重叠时,memcpy会出现错误,而memmove能正确地实施拷贝,但这也增加了一点点开销。memmove的处理措施:(1)当源内存的首地址等于目标内存的首地址时,不进行任何拷贝(2)当源内...
分类:
编程语言 时间:
2015-08-13 11:41:41
阅读次数:
131
/************************************************************************************1.模拟实现memmove函数的实现。(考虑内存重叠)
************************************************************************************/
#include<stdio.h>
#include<stri..
分类:
编程语言 时间:
2015-08-09 18:59:48
阅读次数:
199