# ohos_pool **Repository Path**: wahaha949/ohos_pool ## Basic Information - **Project Name**: ohos_pool - **Description**: No description available - **Primary Language**: Unknown - **License**: BSD-3-Clause - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2025-07-30 - **Last Updated**: 2025-07-31 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # @protobufjs/pool ## 简介 > @protobufjs/pool 是一个通用缓冲池 ## 下载安装 ```shell ohpm install @protobuf/pool ``` OpenHarmony ohpm环境配置等更多内容,请参考 [如何安装OpenHarmony ohpm包](https://gitcode.com/openharmony-tpc/docs/blob/master/OpenHarmony_har_usage.md) 。 ## 使用说明 ### 引用及使用 ``` import {pool} from "@protobuf/pool" const baseAlloc = (size: number) => { hilog.info(0x000, "xxxx", "分配新内存:" + size + ''); logs.push("分配新内存:" + size) return new Uint8Array(size); }; const pooledAlloc = pool(baseAlloc, 4096); function processData() { const buf1: Uint8Array = pooledAlloc(100); hilog.info(0x000, "xxxx", "测试:" + JSON.stringify(buf1)); let test: FixedArray =[1, 2, 3] buf1.set(test,0); const buf2: Uint8Array = pooledAlloc(200); let test2: FixedArray =[4, 5, 6] buf2.set(test2, 0); const buf3 = pooledAlloc(50); logs.push("偏移对齐后:" + buf3.byteOffset) const largeBuf = pooledAlloc(3000); logs.push("缓冲区1:" + '缓冲区1:' + buf1.length) logs.push("缓冲区2:" + '缓冲区2:' + buf2.length) logs.push("大缓冲区:" + '大缓冲区:' + largeBuf.length) } processData(); ``` ## 接口说明 1. 创建通用缓冲池 `pool(alloc: PoolAllocator, slice: PoolSlicer, size?: number): PoolAllocator` ## 约束与限制 在下述版本验证通过: - DevEco Studio: 6.0.0.33, SDK: API20 (6.0.0) ## 目录结构 ```` |---- ohos__pool | |---- entry # 示例代码文件夹 | |---- src/main/ets/page | |---- Index # sample | |---- library | |---- src/main/ets/page | |---- pool.ets # pool核心实现 | |---- README_zh.md # 安装使用方法 | |---- README.OpenSource # 开源说明 | |---- CHANGELOG.md # 更新日志 ```` ## 贡献代码 使用过程中发现任何问题都可以提 [Issue](https://gitee.com/openharmony-tpc-incubate/ohos_pool/issues) 给组件,当然,也非常欢迎发 [PR](https://gitee.com/openharmony-tpc-incubate/ohos_pool/pulls)共建。 ## 开源协议 本项目基于 [BSD License](https://gitee.com/openharmony-tpc-incubate/ohos_pool/blob/master/ohos_pool/LICENSE) ,请自由地享受和参与开源。