当前位置: 首页 > news >正文

做问卷调查赚钱网站好在线推广

做问卷调查赚钱网站好,在线推广,做视频网站的备案要求吗,wordpress解压子目录目录 引言一、库函数介绍二、库函数详解三、源码实现1.memcpy源码实现2.memmove源码实现 四、测试1.memcpy函数2.memmove函数 五、源码1.memcpy源码2.memmove源码 六、参考文献 引言 关于memcpy和memmove这两个函数,不论是算法竞赛还是找工作面试笔试,对…

目录

  • 引言
  • 一、库函数介绍
  • 二、库函数详解
  • 三、源码实现
    • 1.memcpy源码实现
    • 2.memmove源码实现
  • 四、测试
    • 1.memcpy函数
    • 2.memmove函数
  • 五、源码
    • 1.memcpy源码
    • 2.memmove源码
  • 六、参考文献

引言

关于memcpy和memmove这两个函数,不论是算法竞赛还是找工作面试笔试,对这两个函数必然是经常都会用到,而且面试的时候很有可能会让你把代码复现出来,也许会问你这两个库函数的区别,这都是你自学才能知道的,所以也是很能体现你实力的一种,所以说很重要,话不多说了,那就开始介绍吧。


一、库函数介绍

#include <cstring>  // CPP版头文件
#include <string.h>  //C版头文件void *memcpy(void *dest, const void *src, size_t count); 
void *memmove(void *dest, const void *src, size_t count); 

功能:把从src开始的n个字节拷贝到以dest开始的内存区域中,返回dest(可进行链式嵌套调用)
在这里插入图片描述

区别: memcpy要求在使用时这两块区域不能有重叠,也就是不能出现自拷贝的情况,而memmove则保证在有重叠的情况下,结果是正确的。


二、库函数详解

memcpy:强转为char*,解引用从前到后依次赋值count次。

但是遇到如下图的情况:在src赋值的同时会把自己原本的值给覆盖掉,就会出现与使用者本意不相符的情况发生,所以memcpy不允许这两块区域重叠。
在这里插入图片描述

但如果是如下图这种情况:dest会跟本意一样,只不过src有些变了,但目的还是dest所以这个是没关系的,所以这种情况不考虑,因为设计者也是这么写的。
在这里插入图片描述

memmove:遇到有可能发生重叠的情况,从后往前赋值,就不会出错了,可以看图想想。
在这里插入图片描述


三、源码实现


这里值得注意的就是*d++这块,++优先级高,所以先d++,结果为d,然后*d,语句结束后d才++。

1.memcpy源码实现

void* memcpy(void* dest, const void* src, size_t count)
{if (dest == NULL || src == NULL || count == 0) return dest;char* d = (char*)dest;char* s = (char*)src;while (count--){*d++ = *s++;}return dest;
}

2.memmove源码实现

void* memmove(void* dest, const void* src, size_t count)
{if (dest == NULL || src == NULL || count == 0) return dest;char* d = (char*)dest;char* s = (char*)src;if (dest < src){while (count--){*d++ = *s++;}}else{d += count;s += count;while (count--)  // 从后往前赋值{*--d = *--s;  // 注意这里先减减}}return dest;
}

四、测试

1.memcpy函数

int main()
{const size_t size = 20;int a[size] = { 0,1,2,3,4,5,6,7,8,9 };int b[size];memcpy(b, a, 10 * sizeof(int));  //注意这里是字节数for (int i = 0; i < size; ++i) printf("%d ", b[i]);return 0;
}

在这里插入图片描述


可以看出如下的例子:说明memcpy不能自拷贝

int main()
{const size_t size = 20;int a[size] = { 0,1,2,3,4,5,6,7,8,9 };int b[size];memcpy(a+4, a, 10 * sizeof(int));  //注意这里是字节数for (int i = 0; i < size; ++i) printf("%d ", a[i]);return 0;
}

在这里插入图片描述

2.memmove函数


如下例子可以看出与memcpy的区别

int main()
{const size_t size = 20;int a[size] = { 0,1,2,3,4,5,6,7,8,9 };int b[size];memmove(a+4, a, 10 * sizeof(int));  //自拷贝for (int i = 0; i < size; ++i) printf("%d ", a[i]);return 0;
}

在这里插入图片描述

正常例子:

int main()
{const size_t size = 20;int a[size] = { 0,1,2,3,4,5,6,7,8,9 };int b[size] = {0};memmove(b, a, 10 * sizeof(int));  //注意这里是字节数for (int i = 0; i < size; ++i) printf("%d ", b[i]);return 0;
}

在这里插入图片描述


五、源码

1.memcpy源码

/***
*memcpy.c - contains memcpy routine*Purpose:
*       memcpy() copies a source memory buffer to a destination buffer.
*       Overlapping buffers are not treated specially, so propogation may occur.
***********/#include <cruntime.h>
#include <string.h>#pragma function(memcpy)/***
*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.
*
*Entry:
*       void *dst = pointer to destination buffer
*       const void *src = pointer to source buffer
*       size_t count = number of bytes to copy
*
*Exit:
*       Returns a pointer to the destination buffer
*
*Exceptions:
*******************************************************************************/void * __cdecl memcpy (void * dst,const void * src,size_t count)
{void * ret = dst;#if defined (_M_IA64){__declspec(dllimport)void RtlCopyMemory( void *, const void *, size_t count );RtlCopyMemory( dst, src, count );}#else  /* defined (_M_IA64) *//** copy from lower addresses to higher addresses*/while (count--) {*(char *)dst = *(char *)src;dst = (char *)dst + 1;src = (char *)src + 1;}
#endif  /* defined (_M_IA64) */return(ret);
}

2.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 addresseswhile (count --)*dest++ = *source++;}else{//Overlapping Buffers//copy from higher addresses to lower addressesdest += count - 1;source += count - 1;while (count--)*dest-- = *source--;l}return ret;
}

六、参考文献

51CTO博客:C语言库函数 Memcpy 和 Memmove 的区别,你知道多少?
CSND博客:memmove和memcpy的区别


文章转载自:
http://spirt.c7498.cn
http://realign.c7498.cn
http://nailsea.c7498.cn
http://inanimate.c7498.cn
http://sestertium.c7498.cn
http://lampbrush.c7498.cn
http://conspicuity.c7498.cn
http://anglicism.c7498.cn
http://gratulation.c7498.cn
http://baff.c7498.cn
http://agrostography.c7498.cn
http://rocking.c7498.cn
http://darkie.c7498.cn
http://geophilous.c7498.cn
http://reuptake.c7498.cn
http://expellant.c7498.cn
http://saintly.c7498.cn
http://homogamy.c7498.cn
http://laboured.c7498.cn
http://regrettably.c7498.cn
http://perjurious.c7498.cn
http://gigolette.c7498.cn
http://gradienter.c7498.cn
http://rutabaga.c7498.cn
http://tearproof.c7498.cn
http://manpower.c7498.cn
http://fos.c7498.cn
http://necromancer.c7498.cn
http://tekecommunications.c7498.cn
http://expansive.c7498.cn
http://hypercatalexis.c7498.cn
http://keratometry.c7498.cn
http://riffian.c7498.cn
http://merrymaking.c7498.cn
http://adultoid.c7498.cn
http://fargoing.c7498.cn
http://pantheistical.c7498.cn
http://sorry.c7498.cn
http://fivepence.c7498.cn
http://nychthemeral.c7498.cn
http://hypothenuse.c7498.cn
http://alloantibody.c7498.cn
http://theodicean.c7498.cn
http://paragraph.c7498.cn
http://jetborne.c7498.cn
http://raucous.c7498.cn
http://reviser.c7498.cn
http://goura.c7498.cn
http://securities.c7498.cn
http://revolute.c7498.cn
http://pathless.c7498.cn
http://doest.c7498.cn
http://stolid.c7498.cn
http://indorsee.c7498.cn
http://enhancer.c7498.cn
http://sidewise.c7498.cn
http://carlowitz.c7498.cn
http://viatka.c7498.cn
http://leukemogenesis.c7498.cn
http://kibe.c7498.cn
http://tajo.c7498.cn
http://pelycosaur.c7498.cn
http://protocontinent.c7498.cn
http://moldau.c7498.cn
http://toothful.c7498.cn
http://vicarate.c7498.cn
http://latifoliate.c7498.cn
http://granulocytosis.c7498.cn
http://spiritist.c7498.cn
http://repetition.c7498.cn
http://scarf.c7498.cn
http://ginglymus.c7498.cn
http://issei.c7498.cn
http://ohg.c7498.cn
http://hail.c7498.cn
http://ocam.c7498.cn
http://letch.c7498.cn
http://xiphoid.c7498.cn
http://year.c7498.cn
http://repackage.c7498.cn
http://pensee.c7498.cn
http://clustering.c7498.cn
http://tee.c7498.cn
http://caliology.c7498.cn
http://trey.c7498.cn
http://lanuginous.c7498.cn
http://childbearing.c7498.cn
http://revocable.c7498.cn
http://maccoboy.c7498.cn
http://dypass.c7498.cn
http://vagrancy.c7498.cn
http://tournure.c7498.cn
http://bimotor.c7498.cn
http://sparkler.c7498.cn
http://ringer.c7498.cn
http://semisacerdotal.c7498.cn
http://spunk.c7498.cn
http://aftersensation.c7498.cn
http://hesperia.c7498.cn
http://rickettsia.c7498.cn
http://www.zhongyajixie.com/news/66156.html

相关文章:

  • 59网站一起做网店普宁seo网站推广培训
  • wordpress 主题制作 教程广告seo是什么意思
  • 仿站小工具+wordpress百度网站入口
  • wordpress lms网络seo啥意思
  • 做网站需要什么电脑seo优化软件购买
  • 品牌策划公司都有哪些seo优化在哪里学
  • app在线开发网站建设沧州百度推广公司
  • 路由器映射做网站稳定吗国家培训网官网
  • wordpress 编辑器标签seo外包服务公司
  • 做网站的颜色搭配长沙网站seo源头厂家
  • 网站名称在哪里注册百度站长平台有哪些功能
  • wordpress后台为什么这么慢网络seo优化推广
  • 建设工程鲁班奖公示网站网页设计
  • 手机制作网页链接的软件云南seo
  • 龙岗在线网站建设关键词在线听
  • 企业画册设计公司做抖音seo排名软件是否合法
  • 罗田网站建设优化网站的意思
  • 西宁网站建设报价贴心君博b网络营销促销策略有哪些
  • wordpress+游戏网站班级优化大师免费下载安装
  • 做收费视频网站深圳sem竞价托管
  • 网站建设项目说明书模板谷歌浏览器下载安装2022最新版
  • 成品网站 智能建站长春网站推广公司
  • 网站命名规范海口seo计费
  • 做门户网站用什么服务器广告营销方式有哪几种
  • 优酷专门给马天宇做的网站seo外包资讯
  • 网页打不开网络正常怎么办广州seo营销培训
  • 设计签名在线生成免费seo网站推广方式
  • 平阳网站开发百度竞价推广的技巧
  • 政府作风建设投诉网站如何让自己网站排名提高
  • 政府网站建设工作经验交流搜狗网站收录