当前位置:网站首页>内存池(内核角度理解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申请内存,都是向这块空间申请,这样的话,不用进行状态的切换,也不会频繁调用内存处理算法。这块空间我们称之为 内存池!
边栏推荐
- What are the differences between software testers with a monthly salary of 7K and 25K? Leaders look up to you when they master it
- Detailed introduction to the deployment and usage of the Nacos registry
- The testing process that software testers should know
- CFdiv2-Fixed Point Guessing-(区间答案二分)
- Technology sharing | Frida's powerful ability to realize hook functions
- 缺少库while loading shared libraries: libisl.so.15: cannot open shared object file: No such file
- easyExcel
- 小程序開發的部分功能
- Rockchip3399 start auto load driver
- [leetcode] 797 and 1189 (basis of graph theory)
猜你喜欢

Huakaiyun (Zhiyin) | virtual host: what is a virtual host

Query product cases - page rendering data

Deep learning notes (constantly updating...)

Certaines fonctionnalités du développement d'applets

Servlet中数据传到JSP页面使用el表达式${}无法显示问题
![[camera topic] turn a drive to light up the camera](/img/d3/7aabaa5c75813abc4a43820b4c3706.png)
[camera topic] turn a drive to light up the camera

8 free, HD, copyright free video material download websites are recommended

MySQL学习03

Wechat applet development tool post net:: err_ PROXY_ CONNECTION_ Failed agent problem

【Camera专题】OTP数据如何保存在自定义节点中
随机推荐
How to refresh the opening amount of Oracle ERP
Answers to ten questions about automated testing software testers must see
COM和CN
Internal connection query and external connection
[camera topic] how to save OTP data in user-defined nodes
Method of removing webpage scroll bar and inner and outer margins
Comment communiquer avec Huawei Cloud IOT via le Protocole mqtt
elastic stack
Analyzing several common string library functions in C language
How can retail enterprises open the second growth curve under the full link digital transformation
Socket编程
详细些介绍如何通过MQTT协议和华为云物联网进行通信
String replace space
2022 financial product revenue ranking
Kotlin middle process understanding and Practice (II)
Analysis, use and extension of open source API gateway apisex
Comment le chef de file gère - t - il l'équipe en cas d'épidémie? Contributions communautaires
5.文件操作
Depth (penetration) selector:: v-deep/deep/ and > > >
Kotlin middle process understanding and Practice (I)