当前位置:网站首页>内存池(内核角度理解new开辟空间的过程)
内存池(内核角度理解new开辟空间的过程)
2022-07-03 02:11:00 【abs(ln(1+NaN))】
每次我们通过new或者malloc申请200个字节的时候,看起来是OS在堆上给我们开辟了我们需要的大小,实际上略有差异。
int* p = new int[50];
char* p = (char*)malloc(200);
我们在调用new/malloc以后,实际上就会从用户态进入到内核态,假设要申请200个字节,此时如果内存中没有连续的200个字节的空间,OS可能会调用内存处理算法,调整一下其他变量的位置,给我们腾出一大块空间。
我们用户在调用的时候,只管结果,不管过程,但是OS在调用内存处理算法时,是需要耗费时间的,如果后面我们频繁地申请内存,OS也要频繁地调用处理算法,这样做的效率很低,也很耗时。所以为了提升效率,在第一次申请的时候,OS分配的空间大小 > 我们申请的大小。
这块空间放在用户层,每次我们要通过new/malloc申请内存,都是向这块空间申请,这样的话,不用进行状态的切换,也不会频繁调用内存处理算法。这块空间我们称之为 内存池!
边栏推荐
- Summary of ES6 filter() array filtering methods
- SPI机制
- Groovy, "try with resources" construction alternative
- Swift开发学习
- 可视化yolov5格式数据集(labelme json文件)
- His experience in choosing a startup company or a big Internet company may give you some inspiration
- A 30-year-old software tester, who has been unemployed for 4 months, is confused and doesn't know what to do?
- DDL basic operation
- y54.第三章 Kubernetes从入门到精通 -- ingress(二七)
- [shutter] shutter debugging (debugging fallback function | debug method of viewing variables in debugging | console information)
猜你喜欢
Huakaiyun (Zhiyin) | virtual host: what is a virtual host
技术大佬准备就绪,话题C位由你决定
Y54. Chapter III kubernetes from introduction to mastery -- ingress (27)
Learn BeanShell before you dare to say you know JMeter
Redis:Redis的简单使用
stm32F407-------IIC通讯协议
udp接收队列以及多次初始化的测试
深度(穿透)选择器 ::v-deep/deep/及 > > >
微信小程序開發工具 POST net::ERR_PROXY_CONNECTION_FAILED 代理問題
詳細些介紹如何通過MQTT協議和華為雲物聯網進行通信
随机推荐
通达OA 首页门户工作台
[shutter] bottom navigation bar implementation (bottomnavigationbar bottom navigation bar | bottomnavigationbaritem navigation bar entry | pageview)
[Flutter] dart: class;abstract class;factory;类、抽象类、工厂构造函数
力扣(LeetCode)183. 从不订购的客户(2022.07.02)
[shutter] shutter debugging (debugging fallback function | debug method of viewing variables in debugging | console information)
Qt之QComboBox添加QCheckBox(下拉列表框插入复选框,含源码+注释)
Explore the conversion between PX pixels and Pt pounds, mm and MM
机器学习流程与方法
微信小程序开发工具 POST net::ERR_PROXY_CONNECTION_FAILED 代理问题
Problems encountered in small program development of dark horse shopping mall
Introduce in detail how to communicate with Huawei cloud IOT through mqtt protocol
疫情當頭,作為Leader如何進行團隊的管理?| 社區征文
When the epidemic comes, how to manage the team as a leader| Community essay solicitation
Machine learning notes (constantly updating...)
Visual yolov5 format data set (labelme JSON file)
缺少库while loading shared libraries: libisl.so.15: cannot open shared object file: No such file
[Yu Yue education] Jiujiang University material analysis and testing technology reference
In the face of difficult SQL requirements, HQL is not afraid
How can retail enterprises open the second growth curve under the full link digital transformation
2022 financial product revenue ranking