当前位置:网站首页>内存池(内核角度理解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申请内存,都是向这块空间申请,这样的话,不用进行状态的切换,也不会频繁调用内存处理算法。这块空间我们称之为 内存池!
边栏推荐
- 微信小程序开发工具 POST net::ERR_PROXY_CONNECTION_FAILED 代理问题
- Leetcode (540) -- a single element in an ordered array
- [Yu Yue education] China Ocean University job search OMG reference
- Socket programming
- Leetcode 183 Customers who never order (2022.07.02)
- Storage basic operation
- Button button adaptive size of wechat applet
- 机器学习流程与方法
- Anna: Beibei, can you draw?
- How do browsers render pages?
猜你喜欢

Trial setup and use of idea GoLand development tool

The testing process that software testers should know

udp接收队列以及多次初始化的测试

微信小程序开发工具 POST net::ERR_PROXY_CONNECTION_FAILED 代理问题
![[leetcode] 797 and 1189 (basis of graph theory)](/img/2a/9c0a904151a17c2d23dea9ad04dbfe.jpg)
[leetcode] 797 and 1189 (basis of graph theory)

How do it students find short-term internships? Which is better, short-term internship or long-term internship?

LabVIEW安装第三方VISA软件后NI VISA失效
![[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)

Y54. Chapter III kubernetes from introduction to mastery -- ingress (27)

Performance test | script template sorting, tool sorting and result analysis
随机推荐
How can retail enterprises open the second growth curve under the full link digital transformation
Caused by: com. fasterxml. jackson. databind. exc.MismatchedInputException: Cannot construct instance o
[camera topic] how to save OTP data in user-defined nodes
缺少库while loading shared libraries: libisl.so.15: cannot open shared object file: No such file
[leetcode] 797 and 1189 (basis of graph theory)
Detailed introduction to the usage of Nacos configuration center
[camera topic] turn a drive to light up the camera
Distributed transaction solution
[shutter] hero animation (hero realizes radial animation | hero component createrecttween setting)
【Camera专题】手把手撸一份驱动 到 点亮Camera
Technology sharing | Frida's powerful ability to realize hook functions
Detailed introduction to the deployment and usage of the Nacos registry
Answers to ten questions about automated testing software testers must see
Swift开发学习
require.context
Cfdiv2 Fixed Point Guessing - (2 points for Interval answer)
Leetcode (540) -- a single element in an ordered array
Unrecognized SSL message, plaintext connection?
502 (bad gateway) causes and Solutions
Socket编程