C语言内存管理及经典算法

C语言内存管理及经典算法

ID:38256132

大小:236.52 KB

页数:77页

时间:2019-06-07

C语言内存管理及经典算法_第1页
C语言内存管理及经典算法_第2页
C语言内存管理及经典算法_第3页
C语言内存管理及经典算法_第4页
C语言内存管理及经典算法_第5页
资源描述:

《C语言内存管理及经典算法》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、C语言内存管理对于一个c/c++程序员来说,内存泄漏是一个常见的也是令人头疼的问题,为了应对这个问题,有许多技术被研究出来来解决这个问题,例如SmartPointer,GarbageCollection等。一般我们常说的内存泄漏是指堆内存的泄漏。那么为什么会导致内存泄漏呢?通过学习内存管理,相信你一定能解决好这个问题。1-1C语言内存管理方式在进入本专题前,我们先看一下下面的程序,来简单分析以下C语言的内存管理:#include#include//全局变量定义intiGlobalInt1=0;intiGlobalInt

2、2=0;intiGlobalInt3=0;//全局常量定义constintiGlobalConstInt1=1;constintiGlobalConstInt2=5;constintiGlobalConstInt3=6;//全局静态变量定义staticintiGlobalStaticInt1=0;staticintiGlobalStaticInt2=0;staticintiGlobalStaticInt3=0;//函数定义voidfuncParamTest(intiFuncParam1,intiFuncParam2,intiFuncParam3){//函数

3、私有变量定义intiLocalInt1=iFuncParam1;intiLocalInt2=iFuncParam2;intiLocalInt3=iFuncParam3;printf("函数参数变量内存地址");printf("iFuncParam1=0x%08x",&iFuncParam1);printf("iFuncParam2=0x%08x",&iFuncParam2);printf("iFuncParam3=0x%08x",&iFuncParam3);printf("函数本地变量的内存地址");printf("iLocalIn

4、t1=0x%08x",&iLocalInt1);printf("iLocalInt2=0x%08x",&iLocalInt2);printf("iLocalInt3=0x%08x",&iLocalInt3);return;}//入口函数intmain(intargc,char*argv[]){//局部静态变量staticintiStaticInt1=0;staticintiStaticInt2=0;staticintiStaticInt3=0;//局部静态常量定义conststaticintiConstStaticInt1=0;consts

5、taticintiConstStaticInt2=0;conststaticintiConstStaticInt3=0;//局部常量constintiConstInt1=1;constintiConstInt2=5;constintiConstInt3=6;//局部变量intiLocalInt1=0;intiLocalInt2=0;intiLocalInt3=0;char*pMalloc1,*pMalloc2,*pMalloc3;char*pNew1,*pNew2,*pNew3;printf("全局常量的内存地址");printf("iGlobalCo

6、nstInt1=0x%08x",&iGlobalConstInt1);printf("iGlobalConstInt2=0x%08x",&iGlobalConstInt2);printf("iGlobalConstInt3=0x%08x",&iGlobalConstInt3);printf("iConstStaticInt1=0x%08x",&iConstStaticInt1);printf("iConstStaticInt2=0x%08x",&iConstStaticInt2);printf("iConstStaticInt3=0

7、x%08x",&iConstStaticInt3);printf("全局变量的内存地址");printf("iGlobalInt1=0x%08x",&iGlobalInt1);printf("iGlobalInt2=0x%08x",&iGlobalInt2);printf("iGlobalInt3=0x%08x",&iGlobalInt3);printf("静态变量的内存地址");printf("iGlobalStaticInt1=0x%08x",&iGlobalStaticInt1);printf("iGlobalSt

8、aticInt2=0x%08x",&iGlobalStatic

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。