当前位置:网站首页>内存池(内核角度理解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申请内存,都是向这块空间申请,这样的话,不用进行状态的切换,也不会频繁调用内存处理算法。这块空间我们称之为 内存池!
边栏推荐
- [fluent] fluent debugging (debug debugging window | viewing mobile phone log information | setting normal breakpoints | setting expression breakpoints)
- What are the key points often asked in the redis interview
- Solution for processing overtime orders (Overtime unpaid)
- 创建+注册 子应用_定义路由,全局路由与子路由
- [camera topic] complete analysis of camera dtsi
- Comment le chef de file gère - t - il l'équipe en cas d'épidémie? Contributions communautaires
- 转载收录6.5大侠写的部分Qt开发经验
- Servlet中数据传到JSP页面使用el表达式${}无法显示问题
- When the epidemic comes, how to manage the team as a leader| Community essay solicitation
- What are the differences between software testers with a monthly salary of 7K and 25K? Leaders look up to you when they master it
猜你喜欢
elastic stack
通达OA v12流程中心
Certaines fonctionnalités du développement d'applets
Machine learning notes (constantly updating...)
Job object of collaboration in kotlin
Introduce in detail how to communicate with Huawei cloud IOT through mqtt protocol
Hard core observation 547 large neural network may be beginning to become aware?
PyTorch 卷积网络正则化 DropBlock
8 free, HD, copyright free video material download websites are recommended
RestCloud ETL 跨库数据聚合运算
随机推荐
Reprint some Qt development experience written by great Xia 6.5
可视化yolov5格式数据集(labelme json文件)
easyExcel
力扣(LeetCode)183. 从不订购的客户(2022.07.02)
去除网页滚动条方法以及内外边距
leetcode961. Find the elements repeated N times in the array with length 2n
全链路数字化转型下,零售企业如何打开第二增长曲线
各国Web3现状与未来
Basic operation of view
In 2022, 95% of the three most common misunderstandings in software testing were recruited. Are you that 5%?
When the epidemic comes, how to manage the team as a leader| Community essay solicitation
stm32F407-------DMA
LabVIEW安装第三方VISA软件后NI VISA失效
DQL basic operation
Flink CDC mongoDB 使用及Flink sql解析monggo中复杂嵌套JSON数据实现
Stm32f407 ------- IIC communication protocol
疫情当头,作为Leader如何进行团队的管理?| 社区征文
How do browsers render pages?
Caused by: com. fasterxml. jackson. databind. exc.MismatchedInputException: Cannot construct instance o
RestCloud ETL 跨库数据聚合运算