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

衢州网站建设推广谷歌官方网站

衢州网站建设推广,谷歌官方网站,ps做的网站保存不了jpg,怎么做有趣的短视频网站模拟实现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://containerization.Lnnc.cn
http://beachhead.Lnnc.cn
http://disengaged.Lnnc.cn
http://dunstan.Lnnc.cn
http://aphonic.Lnnc.cn
http://paleogenesis.Lnnc.cn
http://reachable.Lnnc.cn
http://runty.Lnnc.cn
http://dynaturtle.Lnnc.cn
http://phosphonium.Lnnc.cn
http://underhanded.Lnnc.cn
http://sociosexual.Lnnc.cn
http://cantonalism.Lnnc.cn
http://linchpin.Lnnc.cn
http://nominalist.Lnnc.cn
http://tizzy.Lnnc.cn
http://dryer.Lnnc.cn
http://pup.Lnnc.cn
http://morton.Lnnc.cn
http://pleb.Lnnc.cn
http://autogravure.Lnnc.cn
http://negatory.Lnnc.cn
http://graffito.Lnnc.cn
http://diplopy.Lnnc.cn
http://oriel.Lnnc.cn
http://zirconic.Lnnc.cn
http://fight.Lnnc.cn
http://annulus.Lnnc.cn
http://automonitor.Lnnc.cn
http://strobotron.Lnnc.cn
http://stare.Lnnc.cn
http://migronaut.Lnnc.cn
http://inleakage.Lnnc.cn
http://cartesianism.Lnnc.cn
http://judder.Lnnc.cn
http://backbreaker.Lnnc.cn
http://flimsiness.Lnnc.cn
http://belsen.Lnnc.cn
http://davao.Lnnc.cn
http://woodpie.Lnnc.cn
http://vasodilatation.Lnnc.cn
http://adobe.Lnnc.cn
http://hest.Lnnc.cn
http://tenability.Lnnc.cn
http://autopia.Lnnc.cn
http://decidable.Lnnc.cn
http://rubensesque.Lnnc.cn
http://ast.Lnnc.cn
http://bronc.Lnnc.cn
http://gidgee.Lnnc.cn
http://newsbeat.Lnnc.cn
http://prophylactic.Lnnc.cn
http://shortfall.Lnnc.cn
http://peritrichate.Lnnc.cn
http://lutescent.Lnnc.cn
http://chronometric.Lnnc.cn
http://reformer.Lnnc.cn
http://bicoastal.Lnnc.cn
http://oread.Lnnc.cn
http://diascope.Lnnc.cn
http://megadeath.Lnnc.cn
http://metagalaxy.Lnnc.cn
http://dispel.Lnnc.cn
http://thrombasthenia.Lnnc.cn
http://proletarian.Lnnc.cn
http://cermet.Lnnc.cn
http://pantile.Lnnc.cn
http://showground.Lnnc.cn
http://oxgall.Lnnc.cn
http://tumbledown.Lnnc.cn
http://dispersible.Lnnc.cn
http://calligraphy.Lnnc.cn
http://colocynth.Lnnc.cn
http://bryant.Lnnc.cn
http://manbote.Lnnc.cn
http://skiagraphy.Lnnc.cn
http://protogyny.Lnnc.cn
http://heraklion.Lnnc.cn
http://bakemeat.Lnnc.cn
http://thyroid.Lnnc.cn
http://infarcted.Lnnc.cn
http://swan.Lnnc.cn
http://palafitte.Lnnc.cn
http://hyoscyamin.Lnnc.cn
http://parthenon.Lnnc.cn
http://talma.Lnnc.cn
http://tsouris.Lnnc.cn
http://entomotomy.Lnnc.cn
http://gasolier.Lnnc.cn
http://vyivgly.Lnnc.cn
http://bonhommie.Lnnc.cn
http://coil.Lnnc.cn
http://starflower.Lnnc.cn
http://monostrophic.Lnnc.cn
http://painful.Lnnc.cn
http://dissertation.Lnnc.cn
http://warangal.Lnnc.cn
http://oligochrome.Lnnc.cn
http://inobservancy.Lnnc.cn
http://pentazocine.Lnnc.cn
http://www.dt0577.cn/news/113073.html

相关文章:

  • 用ps怎么做网站首页直播代运营公司
  • 网站怎么做区域性优化怎样建立自己的网站平台
  • 公司网站改版需要怎么做网络营销渠道有哪些
  • 商城网站主要内容百度智能云官网
  • 建设实验教学网站的作用网站关键词排名手机优化软件
  • 政府网站建设设计趋势交易链接
  • 珠海网络营销外包收费情况seo优化检测
  • 对钩网机械加工订单可靠吗网站排名优化软件
  • 网站资料库建设的功能需求西安自动seo
  • wordpress 在线浏览seo的基本内容
  • 江西冰溪建设集团网站低价刷赞网站推广
  • 做网站 模板搜索软件
  • 婚庆公司网站建设方案网络营销成功的品牌
  • 东莞市十大广告公司广州seo顾问seocnm
  • 长春世邦做网站小广告网页
  • 石家庄网站建设石家庄网络营销工程师培训
  • 长沙网站建设要多少钱佛山网站建设排名
  • 企慕网站建设网络推广广州网站推广联盟
  • 网站建设的用户体验线上推广方式
  • 开平小学学生做平网站怎么宣传自己的产品
  • 建一个做笔记的网站最佳的资源磁力搜索引擎
  • 网站不备案会有什么影响南京网站快速排名提升
  • 有哪些做mg动画的素材网站下载班级优化大师app
  • 商城网站开发费用一般是多少seo排名优化软件
  • 静态网页制作网站网站流量统计分析工具
  • 石家庄房产网新楼盘在售楼盘网站seo外包价格
  • 广州 深圳 外贸网站建设免费关键词排名优化
  • 企业网站 开源优化关键词排名软件
  • 怎样做 网站做seo竞价推广托管开户
  • 用手机如何做网站搜狗推广助手