摘要
为了高效、安全地利用计算机内存资源,在大型的软件设计中,往往要进行大量的内存分配与回收操作,为此,C++专门提供了malloc等相关函数进行操作,这些函数能够满足一般的使用,但由于它们调用了操作系统API,所以实际使用时会在操作系统中产生大量的内存碎片,让内存分配成为效率瓶颈,从而降低系统性能.基于此,通过对循环首次适应算法进行改进,设计并实现了基于C++的高效内存池,大幅提升了内存分配与回收的效率.同时,还为内存池编写了相关的分配子,使其能与C++标准库无缝对接,提供了若干具有垃圾回收功能的智能指针,提高了内存管理与程序运行的效率.
In the development of large scale software,memory allocation and reclaiming usually occur for efficiency and safety. Therefore,C ++ provides special functions for this,such as malloc,etc. These functions can meet the demands of common users. However,these functions call API,so the actual use of these functions produce massive memory fragments in OS and result in the efficiency bottleneck of memory allocation which lowers the system performance. This paper has improved next-fit algorithm and designed a memory pool with efficient strategies based on C ++. The strategies could extremely upgrade the efficiency of memory allocation and reclaiming. Meanwhile,for the perfect connection of memory pool with C ++ standard library,the strategies provide relevant allocators for memory pool. In addition,there are a number of smart pointers which have the function of garbage collection. They can free users from complex and fallible memory management,and improve the efficiency of the program.
出处
《成都大学学报(自然科学版)》
2017年第3期257-261,共5页
Journal of Chengdu University(Natural Science Edition)
基金
四川省科技厅软件科学研究计划(2017ZR0198)
四川省科技厅应用基础计划(2016JY0255)资助项目