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

wordpress自动创建子站网站开发技术有哪些

wordpress自动创建子站,网站开发技术有哪些,阿里巴巴网站怎么做推广方案,汇云网站建设本文为数据结构打下基础 备注:数据结构需要掌握指针,结构体和动态内存管理 目录 6.常见的动态内存的错误 1.对空指针解引用 2.对动态空间的越界访问 3.对非动态内存空间进行free释放 4.使用free只释放开辟的内存空间的一部分 5.对同一块动态内存多次释放 6.动态开辟的…

本文为数据结构打下基础

备注:数据结构需要掌握指针,结构体和动态内存管理

目录

6.常见的动态内存的错误

1.对空指针解引用

2.对动态空间的越界访问

3.对非动态内存空间进行free释放

4.使用free只释放开辟的内存空间的一部分

5.对同一块动态内存多次释放

6.动态开辟的内存忘记释放

7.动态开辟的内存无法释放

代码改进

7.动态内存练习题

1.VS下,求下列代码的执行结果

 答案速查

分析

改进后

方案1

方案2


承接70.【C语言】动态内存管理(重点)(3)文章

6.常见的动态内存的错误

1.对空指针解引用

之前在68.【C语言】动态内存管理(重点)(1)说过

如果真的解引用了, 可能会引发程序崩溃,内存损坏或数据丢失

因此在使用malloc,calloc,recalloc开辟内存空间时,要先判断返回的指针是否为空指针,再做其他操作

2.对动态空间的越界访问

#include <stdlib.h>
int main()
{int* p = (int*)malloc(4);*(p + 1) = 2;*(p + 2) = 3;return 0;
}

打开VS的内存窗口,输入p

显然脱离了动态分配的空间,入侵了其他数据处,可能会引发程序崩溃,内存损坏或数据丢失

3.对非动态内存空间进行free释放

#include <stdlib.h>
int main()
{int a[5] = { 0 };int* p = a;free(p);p = NULL;return 0;
}

导致错误:

 

4.使用free只释放开辟的内存空间的一部分

#include <stdlib.h>
int main()
{int* p = (int*)malloc(20);if (p == NULL){perror("malloc");return 1;//错误返回}for (int i = 0; i < 5; i++)*(p + i) = i;p++;free(p);p = NULL;return 0;
}

 导致错误:

起始的指针不能移动!(上方代码的p++;是禁止使用的,不能改变p的值)

5.对同一块动态内存多次释放

#include <stdlib.h>
int main()
{int* p = (int*)malloc(20);if (p == NULL){perror("malloc");return 1;//错误返回}free(p);free(p);p = NULL;return 0;
}

 导致错误:

如果非要多次释放,在第一次释放后使p置NULL,再free(p);

    free(p);p = NULL;free(p);

 free(NULL);时,free函数什么也不做(free函数具体参见69.【C语言】动态内存管理(重点)(2))

6.动态开辟的内存忘记释放

忘记释放导致该内存不能再使用,可能会造成内存泄漏,程序性能下降,系统资源耗尽,程序崩溃问题

7.动态开辟的内存无法释放

#include <stdlib.h>
void function()
{int* p = (int*)malloc(20);if (p == NULL){perror("malloc");return 1;//错误返回}//使用//......
}int main()
{function();free(p);return 0;
}

function函数内的p是局部变量,函数执行结束时,局部变量被销毁(找不到动态内存的地址),交换给操作系统,如果此时在main函数里free(p);编译无法通过,无法释放空间

(具体介绍局部变量的特性见4.【C语言】初识常量与变量)

同样的,无法释放导致该内存不能再使用,可能会造成内存泄漏,程序性能下降,系统资源耗尽,程序崩溃问题

代码改进

在function函数中返回p

#include <stdlib.h>
int* function()
{int* p = (int*)malloc(20);if (p == NULL){perror("malloc");return 1;//错误返回}//使用//......return p;
}int main()
{//r_p是return_pointer的缩写int* r_p=function();free(r_p);r_p = NULL;return 0;
}

因此

1.在函数中开辟的动态内存空间一定要返回动态内存空间的起始地址,用于main的free函数释放;

2.malloc和free成对使用;calloc和free成对使用(如果是在自定义函数中,则一定要在其返回前使用free)

7.动态内存练习题

1.VS下,求下列代码的执行结果

#define _CRT_SECURE_NO_WARNINGS 
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
void GetMemory(char* p)
{p = (char*)malloc(100);
}void Test(void)
{char* str = NULL;GetMemory(str);strcpy(str, "hello world");printf(str);
}int main()
{Test();return 0;
}

 答案速查

程序崩溃

分析

运行到strcpy处发生错误

注意到0x00000000,这实际上是空指针,说明str还是空指针,进一步推导得出:GetMemory并没有改变str的内容,该函数调用结束,p被销毁,即传值调用

(有关传值调用和传址调用的介绍见29.【C语言】函数系列中 自定义函数)

因此:strcpy(str, "hello world");等价为strcpy(NULL, "hello world");

在51.【C语言】字符函数和字符串函数(strcpy函数)文中提到过,strcpy函数的参数不接受空指针,因此这里会报错

而且printf(str);实际上是对空指针解引用,这是本文介绍的6.常见的动态内存的错误的第1点错误

除此之外,该代码有两处明显不规范的地方:

1.malloc函数的返回值没有判断是否为空指针

2.有malloc但没有free,容易发生内存泄漏

改进后
方案1

使用传址(GetMemory(&str);)调用,p为二级指针(接收str指针的指针)

#define _CRT_SECURE_NO_WARNINGS 
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
void GetMemory(char** p)
{*p = (char*)malloc(100);
}int Test(void)
{char* str = NULL;GetMemory(&str);if (str == NULL){perror("malloc");return 1;//错误返回}strcpy(str, "hello world");printf(str);free(str);str = NULL;return 0;
}int main()
{Test();return 0;
}
方案2

p为一级指针,此时GetMemory无需参数

#define _CRT_SECURE_NO_WARNINGS 
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
char* GetMemory()
{char* p = (char*)malloc(100);return p;
}int Test(void)
{char* str = NULL;str = GetMemory();if (str == NULL){perror("malloc");return 1;}strcpy(str, "hello world");printf(str);free(str);str = NULL;return 0;
}int main()
{Test();return 0;
}


文章转载自:
http://voracity.c7627.cn
http://winston.c7627.cn
http://tasmanian.c7627.cn
http://enchilada.c7627.cn
http://heave.c7627.cn
http://rile.c7627.cn
http://correctitude.c7627.cn
http://archenemy.c7627.cn
http://guam.c7627.cn
http://neuroscience.c7627.cn
http://dystopian.c7627.cn
http://unpack.c7627.cn
http://hypercorrection.c7627.cn
http://vlcc.c7627.cn
http://lookee.c7627.cn
http://bennet.c7627.cn
http://beslobber.c7627.cn
http://reckoner.c7627.cn
http://fishwife.c7627.cn
http://phytolaccaceous.c7627.cn
http://landmass.c7627.cn
http://cromer.c7627.cn
http://digamist.c7627.cn
http://windsock.c7627.cn
http://reedbuck.c7627.cn
http://pleasurably.c7627.cn
http://imprison.c7627.cn
http://reseat.c7627.cn
http://promptbook.c7627.cn
http://misdemeanor.c7627.cn
http://jeffersonian.c7627.cn
http://ironsmith.c7627.cn
http://unstable.c7627.cn
http://lampstandard.c7627.cn
http://geosynclinal.c7627.cn
http://toeshoe.c7627.cn
http://seroconversion.c7627.cn
http://histogenetically.c7627.cn
http://deal.c7627.cn
http://conjunctional.c7627.cn
http://ccc.c7627.cn
http://sheryl.c7627.cn
http://radwaste.c7627.cn
http://tucotuco.c7627.cn
http://reevesite.c7627.cn
http://jehu.c7627.cn
http://rhythmization.c7627.cn
http://lunarnaut.c7627.cn
http://tenpence.c7627.cn
http://eutrapelia.c7627.cn
http://mammectomy.c7627.cn
http://abolitionism.c7627.cn
http://quadrant.c7627.cn
http://dupondius.c7627.cn
http://allose.c7627.cn
http://felice.c7627.cn
http://glycemia.c7627.cn
http://obsecrate.c7627.cn
http://unthinking.c7627.cn
http://eggplant.c7627.cn
http://kedjeree.c7627.cn
http://whipstock.c7627.cn
http://hexosan.c7627.cn
http://externship.c7627.cn
http://aymaran.c7627.cn
http://answer.c7627.cn
http://halfvolley.c7627.cn
http://superficiary.c7627.cn
http://noctilucence.c7627.cn
http://corm.c7627.cn
http://rigid.c7627.cn
http://outspoken.c7627.cn
http://syllabary.c7627.cn
http://hesitance.c7627.cn
http://eurogroup.c7627.cn
http://shipmate.c7627.cn
http://underburn.c7627.cn
http://generalissimo.c7627.cn
http://ens.c7627.cn
http://inhaler.c7627.cn
http://escapeproof.c7627.cn
http://salinelle.c7627.cn
http://sciaenid.c7627.cn
http://orate.c7627.cn
http://exordial.c7627.cn
http://echelette.c7627.cn
http://geopressured.c7627.cn
http://clerihew.c7627.cn
http://cytherea.c7627.cn
http://exiled.c7627.cn
http://quitrent.c7627.cn
http://mummify.c7627.cn
http://sulfurator.c7627.cn
http://beamy.c7627.cn
http://whizz.c7627.cn
http://nafud.c7627.cn
http://laid.c7627.cn
http://slave.c7627.cn
http://evidence.c7627.cn
http://caprifig.c7627.cn
http://www.zhongyajixie.com/news/75645.html

相关文章:

  • 网站开发怎么模拟真实苹果手机的使用电商线上推广
  • 百度竞价推广专员百度seo高级优化
  • 吉祥物在线设计网站优质网站
  • 天津哪家公司做公司网站杭州seo网站建设
  • 福建省政府网站建设方案直通车关键词优化
  • wordpress 双会员系统深圳知名seo公司
  • 河南专业网站建设哪家好南宁网站建设网站推广
  • 网站做seo 反应非常慢网络推广的含义
  • 网站建设实验总结报告网络营销的重要性与意义
  • 珠海中企网站建设黑龙江新闻
  • 维护一个网站一年多少钱seo管理与优化期末试题
  • 佛山做外贸网站渠道青岛百度seo排名
  • 牛商网做网站怎么样360营销平台
  • 东莞网站制作咨询祥奔科技计算机培训机构排名
  • 门户网站开发公司排名站长之家查询网
  • 怎么在一起做网站上拿货北京、广州最新发布
  • 网站在互联网营销中的作用免费网站软件
  • 蒙古文网站建设汇报广告网络
  • 网站开发 图标seo是什么姓氏
  • 长滚动页网站怎么做网站分享
  • 深圳市住房建设局网站香港疫情最新消息
  • 国外的b2b网站或者b2c网站重庆百度推广优化排名
  • 上海搬家公司哪家便宜杭州seo顾问
  • 怎样做cms电影网站赚钱什么是电商平台推广
  • 保定设计网站建设推广普通话手抄报文字
  • 类似抖音网站开发费用今日国内新闻头条
  • 网站登录验证码是怎么做的郑州seo关键词排名优化
  • 二次元网站模板网上国网app推广方案
  • 淮南网络推广报价网站优化推广外包
  • 专业购物网站建设报价营销网络是什么