再开源一款轻量内存池

前两天已开源线程池,开源一款轻量线程池项目,本节继续开源另一个孪生兄弟:内存池。

本节的线程池与内存池代码解析会在我的星球详细讲解。

内存池:https://github.com/Light-City/light-memory-pool

线程池:https://github.com/Light-City/light-thread-pool

基于Arrow的轻量内存池

这个项目的内存池是基于Apache Arrow项目的衍生版本。我们将Arrow项目中复杂的核心结构------内存池------完全剥离出来,形成了这个独立的项目。由于原始的内存池与Arrow项目本身的工具有深度依赖关系,因此我们在这个项目中对内存池进行了一些深度移除和改造,以保持与原始Arrow内存池的基础功能一致。一些改动包括:

  • 分离allocator与memory_pool

  • 移除不需要的LoggingMemoryPool、ProxyMemoryPool

  • 移除jemalloc等第三方malloc库,未来可以支持

通过这些改动,我们的目标是:

  • 使代码更加精简

  • 使内存池更方便地作为其他项目的依赖库使用

  • 提供简单的方式来引入本项目的so库和头文件,以使用内存池功能

此外,这个项目还可以作为深入学习内存池设计与实现的资源。我们欢迎您探索并使用这个经过精心改进的内存池。

1.如何编译

go 复制代码
➜  bazel build //src:memory_pool 
WARNING: Ignoring JAVA_HOME, because it must point to a JDK, not a JRE.
WARNING: Ignoring JAVA_HOME, because it must point to a JDK, not a JRE.
INFO: Analyzed target //src:memory_pool (36 packages loaded, 169 targets configured).
INFO: Found 1 target...
Target //src:memory_pool up-to-date:
  bazel-bin/src/libmemory_pool.a
  bazel-bin/src/libmemory_pool.dylib
INFO: Elapsed time: 1.568s, Critical Path: 1.05s
INFO: 10 processes: 4 internal, 6 darwin-sandbox.
INFO: Build completed successfully, 10 total actions

2.如何使用

所有的用例放在examples目录

2.1 编写一个简单的case

参见:helloworld

go 复制代码
arrow::MemoryPool* pool = arrow::default_memory_pool();

char* val;
arrow::Status status = pool->Allocate(14, reinterpret_cast<uint8_t**>(&val));

if (status.ok()) {
    std::cout << "Memory allocation successful." << std::endl;
    std::strcpy(val, "Hello, World!");
    std::cout << "Filled content: " << val << std::endl;
    pool->Free(reinterpret_cast<uint8_t*>(val), 4);
} else {
    std::cout << "Memory allocation failed." << std::endl;
}

编译:

go 复制代码
➜  bazel build //examples:hello_world 
WARNING: Ignoring JAVA_HOME, because it must point to a JDK, not a JRE.
WARNING: Ignoring JAVA_HOME, because it must point to a JDK, not a JRE.
INFO: Analyzed target //examples:hello_world (0 packages loaded, 2 targets configured).
INFO: Found 1 target...
Target //examples:hello_world up-to-date:
  bazel-bin/examples/hello_world
INFO: Elapsed time: 0.881s, Critical Path: 0.73s
INFO: 7 processes: 5 internal, 2 darwin-sandbox.
INFO: Build completed successfully, 7 total actions

运行:

go 复制代码
➜  bazel-bin/examples/hello_world
Memory allocation successful.
Filled content: Hello, World!

3.如何测试

测试基于catch2编写,所有测试位于tests目录

可以测试tests目录下面的其他测试,只需要替换submit_test为对应的test即可。

go 复制代码
bazel test //tests:memory_pool_test
相关推荐
Ly.Leo7 小时前
时序预测开源项目TimeMachine的布署教程
深度学习·神经网络·ubuntu·开源
SeaTunnel9 小时前
Apache SeaTunnel MySQL CDC 支持按时间启动吗?
大数据·数据库·mysql·开源·apache·seatunnel
FIT2CLOUD飞致云10 小时前
在线地图交互优化,查询组件选项值支持过滤条件,DataEase开源BI工具v2.10.19 LTS版本发布
开源·数据可视化·dataease·bi·数据大屏
血色橄榄枝10 小时前
01 Flutter for OpenHarmony
flutter·开源·鸿蒙
Kitfox AI11 小时前
【100% AI编程一】KitfoxPay:让 NewAPI 无缝接入 Jeepay 的开源支付适配网关
开源·ai编程·oneapi·newapi·jeepay
万岳软件开发小城12 小时前
企业级项目实录:在线教育系统源码如何支撑考试答题小程序开发
开源·源码·在线教育系统源码·教育软件开发·考试刷题软件开发·答题考试系统源码·教育培训小程序开发
edisao13 小时前
【开源】轻量级 LLM 文本质检工具:精准识别核心概念缺失,支持动态别名 + 反馈闭环
大数据·开发语言·人工智能·经验分享·gpt·架构·开源
坠入暮云间x14 小时前
React Native for OpenHarmony开发环境搭建指南(一)
前端·react native·开源
ai产品老杨15 小时前
企业级AI视频管理平台,内置算法商城,集群管理、标注平台开源了
人工智能·开源·音视频
兆龙电子单片机设计15 小时前
【STM32项目开源】STM32单片机智能宠物喂养系统
stm32·单片机·开源·毕业设计·电子信息