当前位置:网站首页>内存池(内核角度理解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申请内存,都是向这块空间申请,这样的话,不用进行状态的切换,也不会频繁调用内存处理算法。这块空间我们称之为 内存池!
边栏推荐
- 【Camera专题】HAL层-addChannel和startChannel简析
- Depth (penetration) selector:: v-deep/deep/ and > > >
- Method of removing webpage scroll bar and inner and outer margins
- 通达OA v12流程中心
- SPI机制
- 机器学习流程与方法
- Visual yolov5 format data set (labelme JSON file)
- 各国Web3现状与未来
- 人脸识别6- face_recognition_py-基于OpenCV使用Haar级联与dlib库进行人脸检测及实时跟踪
- Huakaiyun (Zhiyin) | virtual host: what is a virtual host
猜你喜欢
![[shutter] bottom navigation bar implementation (bottomnavigationbar bottom navigation bar | bottomnavigationbaritem navigation bar entry | pageview)](/img/41/2413af283e8f1db5d20ea845527175.gif)
[shutter] bottom navigation bar implementation (bottomnavigationbar bottom navigation bar | bottomnavigationbaritem navigation bar entry | pageview)

全链路数字化转型下,零售企业如何打开第二增长曲线

微信小程序开发工具 POST net::ERR_PROXY_CONNECTION_FAILED 代理问题

RestCloud ETL 跨库数据聚合运算

Solution for processing overtime orders (Overtime unpaid)

Recommendation letter of "listing situation" -- courage is the most valuable

stm32F407-------DMA
![[shutter] shutter debugging (debugging control related functions | breakpoint management | code operation control)](/img/fe/c053f8d116eb307733177283a26318.png)
[shutter] shutter debugging (debugging control related functions | breakpoint management | code operation control)

stm32F407-------IIC通讯协议

udp接收队列以及多次初始化的测试
随机推荐
COM和CN
[camera topic] complete analysis of camera dtsi
Trial setup and use of idea GoLand development tool
微信小程序开发工具 POST net::ERR_PROXY_CONNECTION_FAILED 代理问题
5.文件操作
疫情當頭,作為Leader如何進行團隊的管理?| 社區征文
Su Shimin: 25 principles of work and life
CFdiv2-Fixed Point Guessing-(区间答案二分)
Hard core observation 547 large neural network may be beginning to become aware?
[Yu Yue education] reference materials of love psychology of China University of mining and technology
单词单词单词
【CodeForces】CF1338A - Powered Addition【二进制】
Kotlin middle process understanding and Practice (I)
[camera topic] turn a drive to light up the camera
Servlet中数据传到JSP页面使用el表达式${}无法显示问题
File class (check)
Exception handling in kotlin process
Comment communiquer avec Huawei Cloud IOT via le Protocole mqtt
Wechat applet Development Tool Post net:: Err Proxy Connexion Problèmes d'agent défectueux
通达OA 首页门户工作台