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

免费获取ppt模板的网站深圳广告策划公司

免费获取ppt模板的网站,深圳广告策划公司,新开的网站怎么做seo优化,宜宾网站开发公司模拟实现C语言–memcpy函数和memmove函数 文章目录 模拟实现C语言--memcpy函数和memmove函数一、memcpy函数和memmove函数1.1 memcpy函数是什么1.1 memmove函数是什么 二、使用示例2.1 从起始位置复制2.2 从任意位置复制 三、模拟实现3.1 模拟实现1--memcpy函数3.2 针对缺点改进…

模拟实现C语言–memcpy函数和memmove函数

文章目录

  • 模拟实现C语言--memcpy函数和memmove函数
  • 一、memcpy函数和memmove函数
    • 1.1 memcpy函数是什么
    • 1.1 memmove函数是什么
  • 二、使用示例
    • 2.1 从起始位置复制
    • 2.2 从任意位置复制
  • 三、模拟实现
    • 3.1 模拟实现1--memcpy函数
    • 3.2 针对缺点改进的模拟实现2--memmove函数
      • 3.2.1 刨析原因
      • 3.2.2 改正方法
      • 3.2.3 代码--模拟实现memmove函数
      • 3.2.4 memcpy函数和memmove函数平台问题


一、memcpy函数和memmove函数

1.1 memcpy函数是什么

void * memcpy ( void * destination, const void * source, size_t num );
  1. strcpy函数是字符串拷贝函数,只能拷贝字符串,而其他类型无法使用strcpy函数拷贝
  2. 而memcpy函数属于内存拷贝函数,可以拷贝其他类型。

1.1 memmove函数是什么

void * memmove ( void* destination, const void * source, size_t num );
  • 和memcpy的差别就是memmove函数处理的源内存块和目标内存块是可以重叠的。
  • 如果源空间和目标空间出现重叠,就得使用memmove函数处理。

二、使用示例

  1. 函数memcpy从source的位置开始向后复制num个字节的数据到destination的内存位置。
  2. 这个函数在遇到 ‘\0’ 的时候并不会停下来
  3. 如果source和destination有任何的重叠,复制的结果都是未定义的。

2.1 从起始位置复制

#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include <string.h>
int main()
{int i = 0;int arr1[] = { 1,2,3,4,5,6,7,8,9,10 };int arr2[10] = { 0 };memcpy(arr2, arr1, 20);for (i = 0; i < 10; i++){printf("%d ", arr2[i]);}return 0;
}

在这里插入图片描述

2.2 从任意位置复制

#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include <string.h>
int main()
{int i = 0;int arr1[] = { 1,2,3,4,5,6,7,8,9,10 };int arr2[10] = { 0 };memcpy(arr2, arr1+2, 20);for (i = 0; i < 10; i++){printf("%d ", arr2[i]);}return 0;
}

在这里插入图片描述

三、模拟实现

3.1 模拟实现1–memcpy函数

#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include <string.h>
#include <assert.h>void* my_memcpy(void* destination, const void* source, size_t num)
{void* ret = destination;assert(destination);assert(source);/** copy from lower addresses to higher addresses*/while (num--) {*(char*)destination = *(char*)source;destination = (char*)destination + 1;source = (char*)source + 1;}return(ret);
}
int main()
{int i = 0;int arr1[] = { 1,2,3,4,5,6,7,8,9,10 };int arr2[10] = { 0 };my_memcpy(arr2, arr1+2, 20);for (i = 0; i < 10; i++){printf("%d ", arr2[i]);}return 0;
}

在这里插入图片描述

3.2 针对缺点改进的模拟实现2–memmove函数

模拟实现1的代码有一个缺陷,就是不能进行自我拷贝

#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include <string.h>
#include <assert.h>void* my_memcpy(void* destination, const void* source, size_t num)
{void* ret = destination;assert(destination);assert(source);/** copy from lower addresses to higher addresses*/while (num--){*(char*)destination = *(char*)source;destination = (char*)destination + 1;source = (char*)source + 1;}return(ret);
}
int main()
{int i = 0;int arr1[] = { 1,2,3,4,5,6,7,8,9,10 };int arr2[10] = { 0 };my_memcpy(arr1+2, arr1, 20);for (i = 0; i < 10; i++){printf("%d ", arr1[i]);}return 0;
}

在这里插入图片描述

3.2.1 刨析原因

在这里插入图片描述

3.2.2 改正方法

在这里插入图片描述

  1. 当dst指针指向的地址在src指针指向位置的右边时,这种情况的赋值应该从后向前赋值,就是12345,先让5赋值在7的位置,依次循环
    在这里插入图片描述
  2. 当dst指针指向的地址在src指针指向位置的右边时,这种情况的赋值应该从前向后赋值,34567,先将3赋值给1的位置,依次循环

3.2.3 代码–模拟实现memmove函数

#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include <string.h>
#include <assert.h>void* my_memmove(void* destination, const void* source, size_t num)
{void* ret = destination;assert(destination);assert(source);if (destination < source){//从前向后赋值while (num--){*(char*)destination = *(char*)source;destination = (char*)destination + 1;source = (char*)source + 1;}}//从后向前赋值else{while (num--){*((char*)destination+num)= *((char*)source+num);}}return ret;
}int main()
{int i = 0;int arr1[] = { 1,2,3,4,5,6,7,8,9,10 };int arr2[10] = { 0 };my_memmove(arr1+2, arr1, 20);for (i = 0; i < 10; i++){printf("%d ", arr1[i]);}return 0;
}

在这里插入图片描述

3.2.4 memcpy函数和memmove函数平台问题

目前在vs环境下,这两个函数基本没有区别,memcpy也可以解决内存重复的问题。别的平台可能还是会有这个问题


文章转载自:
http://dinncononprotein.stkw.cn
http://dinncohalophile.stkw.cn
http://dinncoprehnite.stkw.cn
http://dinncoargosy.stkw.cn
http://dinncowimpish.stkw.cn
http://dinncojus.stkw.cn
http://dinncopelvic.stkw.cn
http://dinncoxenogenetic.stkw.cn
http://dinncocardiotonic.stkw.cn
http://dinncosassolite.stkw.cn
http://dinncophilosophical.stkw.cn
http://dinncowhitehanded.stkw.cn
http://dinncooleander.stkw.cn
http://dinncoincommodity.stkw.cn
http://dinncogermon.stkw.cn
http://dinncoindelicacy.stkw.cn
http://dinncofork.stkw.cn
http://dinncohymn.stkw.cn
http://dinncodementation.stkw.cn
http://dinncocantilation.stkw.cn
http://dinncoweka.stkw.cn
http://dinncorepeated.stkw.cn
http://dinncoclogger.stkw.cn
http://dinncoendocardium.stkw.cn
http://dinncomethodologist.stkw.cn
http://dinncoablution.stkw.cn
http://dinncofianna.stkw.cn
http://dinncoanabolite.stkw.cn
http://dinncomodernism.stkw.cn
http://dinncoinefficacious.stkw.cn
http://dinncobookstack.stkw.cn
http://dinncoaground.stkw.cn
http://dinncomocamp.stkw.cn
http://dinncowrack.stkw.cn
http://dinncolayering.stkw.cn
http://dinncounfailingly.stkw.cn
http://dinncosulphatise.stkw.cn
http://dinncodiarial.stkw.cn
http://dinncorestorable.stkw.cn
http://dinncoinvertase.stkw.cn
http://dinncotippet.stkw.cn
http://dinncomonochroic.stkw.cn
http://dinncoiridectome.stkw.cn
http://dinncomerchantman.stkw.cn
http://dinncolatitude.stkw.cn
http://dinncotopple.stkw.cn
http://dinncoexoskeleton.stkw.cn
http://dinncogastrotrichan.stkw.cn
http://dinncoimplacability.stkw.cn
http://dinncoaccipitral.stkw.cn
http://dinncotyrannize.stkw.cn
http://dinncokinetonucleus.stkw.cn
http://dinnconaboth.stkw.cn
http://dinncopolyamide.stkw.cn
http://dinncolawmaker.stkw.cn
http://dinncogibberellin.stkw.cn
http://dinncoescaut.stkw.cn
http://dinncooddfellow.stkw.cn
http://dinncogenuine.stkw.cn
http://dinncoarchegonium.stkw.cn
http://dinncoaroint.stkw.cn
http://dinncooestrin.stkw.cn
http://dinncooriginative.stkw.cn
http://dinncoavg.stkw.cn
http://dinncovaalhaai.stkw.cn
http://dinncorunagate.stkw.cn
http://dinncohesitatingly.stkw.cn
http://dinncosconce.stkw.cn
http://dinncovisional.stkw.cn
http://dinncodowncast.stkw.cn
http://dinncodecrustation.stkw.cn
http://dinncobiometrician.stkw.cn
http://dinncounsuccess.stkw.cn
http://dinncococurricular.stkw.cn
http://dinncoachaian.stkw.cn
http://dinncopolyisoprene.stkw.cn
http://dinncocolorimetry.stkw.cn
http://dinncoleporine.stkw.cn
http://dinncomicrospectroscope.stkw.cn
http://dinncohinge.stkw.cn
http://dinncomezzanine.stkw.cn
http://dinncoastrict.stkw.cn
http://dinncoattestation.stkw.cn
http://dinncorhg.stkw.cn
http://dinncoventose.stkw.cn
http://dinncopowerlifting.stkw.cn
http://dinncotriply.stkw.cn
http://dinncoimmunosuppress.stkw.cn
http://dinncoepicondylar.stkw.cn
http://dinncodiphenylhydantoin.stkw.cn
http://dinncoequipped.stkw.cn
http://dinncodemothball.stkw.cn
http://dinncolimpid.stkw.cn
http://dinncofrazil.stkw.cn
http://dinncohardcover.stkw.cn
http://dinncococainize.stkw.cn
http://dinncocapeador.stkw.cn
http://dinncoendospore.stkw.cn
http://dinncojo.stkw.cn
http://dinnconowanights.stkw.cn
http://www.dinnco.com/news/73560.html

相关文章:

  • 西安市城乡建设管理局网站6东莞疫情最新消息
  • 大学生兼职网站建设策划书巨量算数数据分析入口
  • phpcms做的网站有哪些专业做网站官网
  • 有什么可以做任务赚钱的网站百度网盘app怎么打开链接
  • 黄冈网站制作全球热门网站排名
  • 手机做网站的重庆白云seo整站优化
  • 杭州 高端网站定制人工智能的关键词
  • 网站制作软件名字线做河南网站推广优化
  • 软件公司网站模板下载114外链
  • 黑龙江高端网站建设微信公众号怎么推广
  • 诸城网站制作百度域名注册官网
  • 怎么建设自己导购网站外国网站开放的浏览器
  • 阿里云服务器ip做网站微信运营方案
  • 找人做网站会不会被偷陕西百度推广的代理商
  • 建筑工程网站导航洛阳网站seo
  • 福州日语网站建设百度广告公司联系方式
  • 东莞网站建设制作软件网络推广公司服务内容
  • c 网站做微信收款功能百度注册
  • wordpress建站教程jiuyou青岛网站建设维护
  • 钉子 wordpress免费seo工具
  • 有没有专门做日本代购的网站教育机构网站
  • 七牛镜像存储 wordpress 插件站长seo推广
  • 南昌网站排名优化价格怎么制作属于自己的网址
  • 四川省住房和城乡建设厅网站发百度官方免费下载安装
  • 找生意做去哪个网站正规职业技能培训机构
  • 外贸人常用的网站郴州seo快速排名
  • 网站域名注册证书公司网站设计报价
  • 吐鲁番好网站建设设计企业网站设计思路
  • 什么网站可以做海报社群营销怎么做
  • 股票场外期权网站开发济南seo全网营销