📄 main.cpp
字号:
#include "memory_pool.hpp"
#include <iostream>
#include "shm_alloc.hpp"
#include <vector>
#include <algorithm>
#include <iterator>
using namespace std;
using namespace happycode;
template< class T >
void print(T i) {cout << i << " ";};
int main()
{
char *heap_mem = new char[10485760];
MemoryPool<256,512> mempool;
try {
mempool.init_mem(heap_mem,10485760);
} catch(mempool_init_error &e) {
cerr << e.what() << endl;
}
shm_allocator<int,256,512>::mempoolptr = &mempool;
vector< int,shm_allocator<int,256,512> > test(40);
test.push_back(1);
test.push_back(10);
test.push_back(5);
test.push_back(3);
cout << mempool.dump() << endl; //use 256 block 4
sort(test.begin(),test.end());
for_each(test.begin(),test.end(),print<int>);
cout << mempool.dump() << endl; //use 256 block 4
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -