https://github.com/quqionfree/quqimemorypool
This is a c++ memory pool.
https://github.com/quqionfree/quqimemorypool
cpp cpp-library cpp11 cpp14 cpp17 cpp20 memory-allocator
Last synced: 4 months ago
JSON representation
This is a c++ memory pool.
- Host: GitHub
- URL: https://github.com/quqionfree/quqimemorypool
- Owner: quqiOnfree
- License: apache-2.0
- Created: 2022-12-10T17:41:20.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-07-19T16:19:11.000Z (12 months ago)
- Last Synced: 2025-01-22T17:45:06.292Z (5 months ago)
- Topics: cpp, cpp-library, cpp11, cpp14, cpp17, cpp20, memory-allocator
- Language: C++
- Homepage:
- Size: 46.9 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 内存池MemoryPool
- 模板类型为class时 使用格式如下
```cppstruct hi
{
hi() {}
vector a;
~hi() {}
};
qmem::SingleDataTypeMemoryPool sd2;
//allocate 获取内存
//自动调用构造函数
hi* qw = sd2.allocate();
//归还内存
sd2.deallocate(qw);```
- 不同内存池之间的性能
```cpp{
//模板类型为class时 使用格式如下
qmem::SingleDataTypeMemoryPool sd2;
//allocate 获取内存
//自动调用构造函数
hi* qw = sd2.allocate();
//归还内存
sd2.deallocate(qw);
}{
//允许单个类型获取内存的内存池,不允许生成数组
//release 获取内存和释放内存平均耗时 1.597e-08s
qmem::SingleDataTypeMemoryPool sd;
clock_t start = clock();
for (size_t i = 0; i < times; ++i)
{
a[i] = sd.allocate();
}
for (size_t i = 0; i < times; ++i)
{
sd.deallocate(a[i]);
}
cout << "SingleDataTypeMemoryPool:" << static_cast(clock() - start) / CLOCKS_PER_SEC / times << '\n';
}{
//标准库内存池
//release 获取内存和释放内存平均耗时 9.122e-08s
allocator stdAllocator;
clock_t start = clock();
for (size_t i = 0; i < times; ++i)
{
a[i] = stdAllocator.allocate(1);
}
for (size_t i = 0; i < times; ++i)
{
stdAllocator.deallocate(a[i], 1);
}
cout << "allocator:" << static_cast(clock() - start) / CLOCKS_PER_SEC / times << '\n';
}```