当前位置:网站首页>内存池(内核角度理解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申请内存,都是向这块空间申请,这样的话,不用进行状态的切换,也不会频繁调用内存处理算法。这块空间我们称之为 内存池!
边栏推荐
- In the face of difficult SQL requirements, HQL is not afraid
- 疫情當頭,作為Leader如何進行團隊的管理?| 社區征文
- LabVIEW安装第三方VISA软件后NI VISA失效
- Detailed introduction to the deployment and usage of the Nacos registry
- stm32F407-------ADC
- [Yu Yue education] China Ocean University job search OMG reference
- 深度学习笔记(持续更新中。。。)
- Iptables layer 4 forwarding
- CFdiv2-Fixed Point Guessing-(区间答案二分)
- 我的创作纪念日
猜你喜欢
A 30-year-old software tester, who has been unemployed for 4 months, is confused and doesn't know what to do?
Certaines fonctionnalités du développement d'applets
What are the key points often asked in the redis interview
Performance test | script template sorting, tool sorting and result analysis
In the face of difficult SQL requirements, HQL is not afraid
深度(穿透)选择器 ::v-deep/deep/及 > > >
stm32F407-------DMA
easyExcel
Depth (penetration) selector:: v-deep/deep/ and > > >
Machine learning notes (constantly updating...)
随机推荐
2022 financial product revenue ranking
Analyzing several common string library functions in C language
File class (add / delete)
Job object of collaboration in kotlin
[shutter] shutter debugging (debugging control related functions | breakpoint management | code operation control)
Technology sharing | Frida's powerful ability to realize hook functions
Bottleneck period must see: how can testers who have worked for 3-5 years avoid detours and break through smoothly
His experience in choosing a startup company or a big Internet company may give you some inspiration
stm32F407-------DMA
Swift development learning
[codeforces] cf1338a - Powered addition [binary]
单词单词单词
5.文件操作
Processing of tree structure data
可视化yolov5格式数据集(labelme json文件)
Wechat applet development tool post net:: err_ PROXY_ CONNECTION_ Failed agent problem
Problems encountered in small program development of dark horse shopping mall
What are the key points often asked in the redis interview
Method of removing webpage scroll bar and inner and outer margins
stm32F407-------ADC