c++ 内存池是什么...
天蓬老师
天蓬老师 2017-04-17 14:27:19
0
4
579

今天在知乎上问题问了一个问题, 轮子哥的回答里面提到的内存池的概念, 但是我其实不太清楚内存池到底是什么? 顺便求知乎提问中问题的解答...
链接如下 : 用c++写正则引擎构造nfa的时候到底该用智能指针吗?

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(4)
伊谢尔伦

1) Apply for a large amount of memory from the operating system at one time, then build your object on top of it, and then return it to the operating system after use, to avoid frequent new delete overhead and memory fragmentation. These are considerations when your program needs performance very much.
2) When using shared_ptr and unique_ptr, you need to understand who owns the resource. For example, if two Nodes are in the same status, their status is equal. At this time, you cannot know which Node should decide when to release the resources, so neither shared_ptr nor unique_ptr meets the application requirements. From an experience point of view, I suggest you implement it in the way of normal pointers, and finally traverse the entire graph to release resources, so that you can focus on implementing program logic.

Peter_Zhu

The overhead of new and delete memory is relatively large, and it is relatively small to directly find a free memory block from the allocated memory array. So allocate a large memory in advance, divide it into small memory blocks, mark it as free when not in use, and retrieve it faster when in use. This is the prototype of the memory pool. I think simple and radical algorithms are indeed more effective, but pools with complex algorithms are not as good as the operating system's own new delete. After all, the operating system is constantly optimizing memory allocation and release algorithms, but it just chooses the most conservative strategy.

左手右手慢动作

For your second question, the easiest way is to use vector as the main structure of the stack. If you need a more sophisticated implementation, you need to write a space configurator yourself (you can refer to the implementation of the double-layer space configurator in SGI STL)

黄舟

The one with the word pool is to create a collection, use a certain algorithm on this collection to optimize performance, memory pool, a lot of memory, manage and utilize it yourself. . Thread pool, many threads, management applications, no need to waste time in creation when using it. Timeliness is better

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!