improved AccumMemoryManager

This commit is contained in:
hyzboy 2024-03-09 20:47:19 +08:00
parent 9265a26b87
commit 924f4ab9f3
2 changed files with 19 additions and 17 deletions

View File

@ -33,7 +33,7 @@ namespace hgl
bool SaveMemoryToFile(const OSString &,int64,const void *,int64); ///<保存一块内存到一个文件
bool IsDirectory(const os_char *);
inline bool IsDirectory(const OSString &str){return IsDirectory(str.c_str());} ///<判断这个名称是否是目录
inline bool IsDirectory(const OSString &str){return IsDirectory(str.c_str());} ///<判断这个名称是否是目录
#if HGL_OS != HGL_OS_Windows
bool IsLink(const os_char *); ///<判断这个名称是否是链接

View File

@ -1,12 +1,13 @@
#pragma once
#pragma once
#include<hgl/type/List.h>
#include<hgl/type/DataArray.h>
namespace hgl
{
/**
* <br>
*
* <br>
*
*/
class AccumMemoryManager
{
@ -20,43 +21,44 @@ namespace hgl
private:
int64 total_bytes=0; ///<总字节数
DataArray<AccumMemoryManager::Block> block_list;
DataArray<char> data_array; ///<数据
List<Block> block_list; ///<数据块列表
DataArray<char> data_array; ///<数据
public:
AccumMemoryManager()=default;
~AccumMemoryManager()=default;
const int64 GetTotalBytes()const{return total_bytes;}
const int64 GetBlockCount()const{return block_list.GetCount();}
const int64 GetTotalBytes()const{return data_array.GetBytes();} ///<取得总共申请的内存总字节数
const int64 GetBlockCount()const{return block_list.GetCount();} ///<取得内存数据块数量
const void *Acquire(const int64 size)
Block *Acquire(const int64 size) ///<申请一块内存
{
if(size<=0)return(nullptr);
Block b;
Block *b=block_list.Add();
b.offset=total_bytes;
b.size=size;
b->offset =data_array.GetBytes();
b->size =size;
data_array.AddCount(size);
return data_array.GetPointer(b.offset);
return b;
}
void *Access(const Block *b) ///<访问一块内存
{
return b?data_array.GetPointer(b->offset):nullptr;
}
void Clear()
{
total_bytes=0;
block_list.Clear();
data_array.Clear();
}
void Free()
{
total_bytes=0;
block_list.Free();
data_array.Free();
}