/** * @file dl_memory.h * @brief 内存操作相关 * * @version 1.0 * @author lveyou * @date 22-05-16 */ #pragma once #include #include "memory/dl_buffer.h" namespace dl::Memory { //-------------------------------------lz4----------------------------------- /** * @brief 压缩数据,使用lz4算法 * @param[in] unzip 原始数据 * @param[in] speed 压缩速度 [0, 1] * @retval 压缩后数据,需要释放内存 * @note 不会失败 */ Buffer CompressLz4(BufferView unzip, double speed = 0.0f); /** * @brief 解压缩数据,使用lz4算法 * @param[in] zip 压缩数据 * @param[in] size_unzip 原始数据大小,为0自动判断,但降低效率 * @retval 原始数据,失败返回nullptr,成功需要手动释放内存 */ Buffer DecompressLz4(BufferView zip, size_t size_unzip = 0); void TestLz4(); /** * @brief memcpy_s的替代品 */ inline void Copy(void* target, size_t size, const void* source, size_t size_source) { if (size < size_source) memcpy(target, source, size); else memcpy(target, source, size_source); } }