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

天美影视传媒广告制作流程上海网络公司seo

天美影视传媒广告制作流程,上海网络公司seo,南昌高端模板建站,网站直播间 是怎么做的内存管理 new/delete C语言 malloc free完成对堆内存的申请和释放。 C new delete 类 new:动态申请存储空间的运算符,返回值为申请空间的对应数据类型的地址 int *p new int(10); 申请了一个初始值为10的整型数据 int *p new int[10]; 申…

内存管理

new/delete

C语言  malloc  free完成对堆内存的申请和释放。

C++  new  delete 类

new:动态申请存储空间的运算符,返回值为申请空间的对应数据类型的地址

int *p = new int(10);  申请了一个初始值为10的整型数据

int *p = new int[10];   申请了能存放10个整型数据元素的数组,其首地址为arr

单变量空间

#include <iostream>
#include <stdlib.h>
using namespace std;//malloc free  # include <stdlib.h>  库函数
//new delete key work 关键字int main()
{//Cint *p = (int*)malloc(sizeof(int));int *p = static_cast<int*>(malloc(sizeof(int)));//C++  单变量空间int *p = new int(200);//*p = 200;cout<<*p<<endl;string *ps = new string("aaa");//*ps = "china";cout<<*ps<<endl;struct Stu{int age;string name;};Stu *pStu = new Stu{10, "bob"};cout<<pStu->age<<endl;cout<<pStu->name<<endl;return 0;
}

多变量空间  数组

#include <iostream>
#include <string.h>  // #include <cstring>
#include <stdlib.h>
using namespace std;int main()
{char* p = new char[4];const char* source = "aa";strcpy_s(p, 4, source);cout << "p: " << p << endl;int *pi = new int[5]{0};memset(pi, 0, sizeof(int[5]));for(int i = 0; i < 5; i++){cout<<pi[i]<<endl;}char **ppc = new char*[5]{NULL};ppc[0] = new char[10];strcpy(ppc[0], "china");ppc[1] = "automan";ppc[2] = "greatwall";while(*ppc){cout<<*ppc++<<endl;}return 0;
}

一维、多维

#include <iostream>
#include <stdlib.h>
#include <string.h>
using namespace std;int main()
{int(*pa)[4] = new int[3][4]{ {0} };for (int i = 0; i < sizeof(int[3][4]) / sizeof(int[4]); i++){for (int j = 0; j < 4; j++){cout << pa[i][j] << "";}cout << endl;}int (*px)[3][4][5] = new int[2][3][4][5];return 0;
}

 内存释放

#include <iostream>
#include <stdlib.h>
#include <string.h>
using namespace std;int main()
{int *p = new int;delete p;int *q = new int[1000];delete []q;//多维只用一个框即可,内核用递归删除int *r = new int[1000][][];delete []r;return 0;
}

内联函数

内联函数inline function

介于宏函数和普通函数之间

宏函数

优点:代码内嵌,避免了函数调用。

缺点:容易产生歧义,易使text段体积增大。

普通函数

优点:一段高度抽象的逻辑,不易产生歧义,使text段体积减小。

缺点:函数调用的压栈与出栈的开销。

inline 内联函数

优点:一段高度抽象的逻辑,不易产生歧义,使text段体积减小,会进行类型检查,避免压栈与出栈的开销。

代价:增加代码段的空间

本质:以牺牲代码段空间为代价,提高程序的运行时间的效率

适用:代码体很小且频繁调用

为何不把所有函数inline?

内嵌太多,inline变成了给编译器的一种建议

只有当函数只有10行甚至更少时才会将其定义为内联函数。

#include <iostream>
using namespace std;#define SQR(i) ((i)*(i))  //宏函数int sqr(i)  //普通函数
{return i * i;
}inline int sqr(i)
{return i * i;
}int main()
{int i = 0;while(i < 5){cout<<SQR(i++)<<endl;}return 0;
}

强制类型转换

#include <iostream>
#include <stdlib.h>using namespace std;void func(int & v)
{cout<<v<<endl;
}int main()
{static_cast  对于隐式类型可以转化的,即可用此类型float a = 5.6;int b = 5;//隐式类型转换a = b;b = a;b = static_cast<int>(a);a = static_cast<float>(b);void *p; int *q;p = q;q = p;  //报错q = static_cast<int*>(p);int x = 10;int y = 3;float z = static_cast<float>(x) / y;char * pc = static_cast<char*>(malloc(100));reinterpret_cast  对于无隐式的类型转化,static_cast不可用char * p; int * q;p = reinterpret_cast<char*>(q);int a[5] = {1, 2, 3, 4, 5};int *p = (int*)((int)a+1);int *p = reinterpret_cast<int*>((reinterpret_cast<int>(a) + 1));cout<<hex<<*p<<endl;const_cast  脱常,只能应用于指针和引用const 修饰的一定不可以改const int a = 19;func(const_cast<int&>(a));dynamic_castreturn 0;
}

宏,在预处理阶段发生了替换

常量编译阶段发生了替换

常量不变

命名空间

命名空间为大型项目开发,避免命名冲突的一种机制。

:: 作用域运算符,前面要命名空间

全局无名命名空间

局部

namespace  是对全局命名空间的再次划分。

#include <iostream>using namespace std;int v = 55;  // 全局int main()
{int b = 10;  // 局部int *p = &v;cout<<v<<endl;cout<<b<<endl;cout<<::<<endl;return 0;
}

#include <iostream>using namespace std;namespace Space{int x;void func(){printf("void func");}struct Stu{int a;int b;}
}namespace Other{int x;int y;
}int main()
{Space::x = 200;cout<<Space::x<<endl;using Space::x;x = 20;cout<<x<<endl;using namespace Space;Stu s = {1, 2};cout << s.a << "---" << endl;using namespace Other;Other::x = 10;y = 20;cout<<Other::x<<y<<endl;int m, n;std::cin>>m>>n;std::cout<<m<<n<<std::endl;return 0;
}

如果有局部变量名相同,冲突

支持嵌套

#include <iostream>using namespace std;namespace Space{int a;int b;namespace Other{int m;int n;}
}int main()
{using namespace Space::Other;m = 20;return 0;
}

协作开发

#include <iostream>using namespace std;namespace Space
{int x;
}namespace Space
{int y;
}int main()
{using namespace Space;int x = 10;int y = 20;cout<<x<<y<<endl;return 0;
}

相同空间名会合并

String类

#include <iostream>using namespace std;//string 不是关键字,而是一个类int main()
{std::string str;string str("china");string str = "china";str = "good";string str2(str);cout<<str<<endl;cout<<str2<<endl;string s = "china";s[3] = 'w';cout<<s<<endl;char buf[1024];strcpy(buf, s.c_str());  //string -> char* c_str返回字符串cout<<buf<<endl;str.swap(str2);  //交换两个字符串  swap 成员函数int n = str.find('i', 0); //查找一个字符的位置,返回下标,找不到返回-1cout<<"n = "<<n<<endl;string sArray[10] = {"0","1","22","333","4444","55555","666666","7777777","88888888","999999999",};for(int i = 0; i < 10; i++){cout<<sArray[i]<<endl;}return 0;
}

总结

malloc free C库函数  ;  new delete  new[]  delete[] 关键字

new delete > malloc free

申请单变量空间

申请数组  一维  多维

#include <iostream>using namespace std;struct Str
{char *p;
};int main()
{string *ps = new string;*ps = "china";cout<<ps<<endl;   //输出地址  对象的地址cout<<*ps<<endl;  //输出值    对象的内容struct Str str = {"abcdefg"};int *pi = new int[10]{0};char **ppc = new int*[5]{NULL};  //定义指针数组int (*p)[4] = new int[3][4];return 0;
}

erase(0, npos)

从0开始,一直删除到' '位置

str.erase(0, str.find_first_not_of(' '));

下标后,往后删除

str.erase(str.find_last_not_of(' ') + 1);

#include <iostream>
#include <string.h>
#include <stdlib.h>using namespace std;int main()
{FILE *fp = fopen("aa.txt", "r+");  //打开并读取文件if(fp == NULL)return -1;vector<string> vs;char buf[1024];while(fgets(buf, 1024, fp) != NULL)  //读取文件内容{vs.push_back(buf);  // 内容接在后边}for(int i = 0; i < vs.size(); i++){cout<<vs[i]<<endl;}fclose(fp);return 0;    
}

http://www.yidumall.com/news/33660.html

相关文章:

  • 每日数码科技新鲜事西安seo王
  • wordpress 获取分类名称seo优化名词解释
  • 做新媒体每天必看的网站seo发帖软件
  • 网站开发的未来发展成品影视app开发
  • wordpress 迷淘seo优化总结
  • 深圳高端网站建设美工百度搜索风云榜排名
  • 优秀网站页面设计图片网络营销所学课程
  • 网站建设哈尔滨网站设计3一键注册所有网站
  • 免费建自己的网站赚钱万能优化大师下载
  • 建设银行etc官方网站网络营销概念是什么
  • 后台做网站的题seo常用方法
  • 旅游网站开发与设计论文百度提交
  • 旅游局网站建设解决方案没干过网络推广能干吗
  • 我被朋友拉进彩票网站说做代理产品设计公司
  • vps搭建网站需要空间手机百度下载安装
  • 建站程序大全百度收录网站需要多久
  • 网站建设培训课程2020年十大关键词
  • 上海推广平台有哪些电商seo优化是什么意思
  • 住房和城乡建设部招聘一个企业seo网站的优化流程
  • 百度上公司做网站网络营销个人感悟小结
  • 网站建设的报价湖北seo服务
  • 免费的公司网站怎么做域名注册服务网站哪个好
  • 一些好用的网站谷歌关键词搜索工具
  • 南昌网站建设公司排行榜前十惠州百度关键词优化
  • 南京网络推广网站深圳网络推广有几种方法
  • 手机网站图片自适应代码本地免费发布信息网站
  • 网站建设公司山西专业网站优化培训
  • 大兴网站建设公司百度资源分享网
  • 徐州网站建设青州陈酿化妆品营销推广方案
  • 如何制作企业官网泉州百度推广排名优化