__gnu_cxx 中__pool_alloc内存分配器的使用

__pool_alloc内部使用链表进行管理内存、预分配内存、不归还内存给操作系统等机制来减少malloc的调用次数。

下面是一个简单的使用案例

#include<iostream>
#include<vector>
#include<string>
#include<ext/pool_allocator.h>

int main()
{
    int nLoop = 0;
    std::cin >> nLoop;
    std::vector<int, __gnu_cxx::__pool_alloc<int> > vec;
    for (int i = 0; i < nLoop; i++) {
        vec.push_back(i);
    }

    std::cout << "allo end\n";
    std::string str;
    std::cin >> str;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/guoguangwu/article/details/89375457
今日推荐