当前位置:网站首页>内存池(内核角度理解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申请内存,都是向这块空间申请,这样的话,不用进行状态的切换,也不会频繁调用内存处理算法。这块空间我们称之为 内存池!
边栏推荐
- Comment communiquer avec Huawei Cloud IOT via le Protocole mqtt
- String replace space
- Bottleneck period must see: how can testers who have worked for 3-5 years avoid detours and break through smoothly
- stm32F407-------DMA
- stm32F407-------ADC
- [shutter] shutter debugging (debugging control related functions | breakpoint management | code operation control)
- COM和CN
- What are the differences between software testers with a monthly salary of 7K and 25K? Leaders look up to you when they master it
- [leetcode] 797 and 1189 (basis of graph theory)
- Huakaiyun | virtual host: IP, subnet mask, gateway, default gateway
猜你喜欢

返回一个树形结构数据

Certaines fonctionnalités du développement d'applets

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

Technology sharing | Frida's powerful ability to realize hook functions

Trial setup and use of idea GoLand development tool
![[camera topic] complete analysis of camera dtsi](/img/cb/d42589fcf0610600c9dc8c7992d4d7.png)
[camera topic] complete analysis of camera dtsi

深度学习笔记(持续更新中。。。)
![[leetcode] 797 and 1189 (basis of graph theory)](/img/2a/9c0a904151a17c2d23dea9ad04dbfe.jpg)
[leetcode] 797 and 1189 (basis of graph theory)

A 30-year-old software tester, who has been unemployed for 4 months, is confused and doesn't know what to do?

Performance test | script template sorting, tool sorting and result analysis
随机推荐
iptables 4层转发
Socket编程
Su Shimin: 25 principles of work and life
[shutter] shutter debugging (debugging fallback function | debug method of viewing variables in debugging | console information)
Leetcode (540) -- a single element in an ordered array
详细些介绍如何通过MQTT协议和华为云物联网进行通信
Introduce in detail how to communicate with Huawei cloud IOT through mqtt protocol
leetcode961. Find the elements repeated N times in the array with length 2n
Internal connection query and external connection
Distributed transaction solution
Answers to ten questions about automated testing software testers must see
Caused by: com. fasterxml. jackson. databind. exc.MismatchedInputException: Cannot construct instance o
Recommendation letter of "listing situation" -- courage is the most valuable
502 (bad gateway) causes and Solutions
Bottleneck period must see: how can testers who have worked for 3-5 years avoid detours and break through smoothly
微信小程序開發工具 POST net::ERR_PROXY_CONNECTION_FAILED 代理問題
Solution for processing overtime orders (Overtime unpaid)
通达OA v12流程中心
[camera topic] complete analysis of camera dtsi
How to find summer technical internship in junior year? Are you looking for a large company or a small company for technical internship?