added Write function in AbstractMemoryAllocator<> and MemoryAllocator class.

This commit is contained in:
hyzboy 2024-03-26 01:19:08 +08:00
parent 003bae2c24
commit cf13064cea

View File

@ -54,6 +54,7 @@ namespace hgl
bool Alloc (const uint64); ///<分配指定长度的空间 bool Alloc (const uint64); ///<分配指定长度的空间
virtual void Free ()=0; ///<释放数据空间 virtual void Free ()=0; ///<释放数据空间
virtual void Clear (){data_size=0;} virtual void Clear (){data_size=0;}
virtual bool Write (const void *source,const uint64 offset,const uint64 size)=0;
};//class AbstractMemoryAllocator };//class AbstractMemoryAllocator
class MemoryAllocator:public AbstractMemoryAllocator class MemoryAllocator:public AbstractMemoryAllocator
@ -71,6 +72,17 @@ namespace hgl
using AbstractMemoryAllocator::AbstractMemoryAllocator; using AbstractMemoryAllocator::AbstractMemoryAllocator;
virtual ~MemoryAllocator(); virtual ~MemoryAllocator();
virtual void Free() override; virtual void Free() override;
virtual bool Write(const void *source,const uint64 offset,const uint64 size) override
{
if(!source||size==0)return(false);
if(offset+size>data_size)
return(false);
memcpy((uint8 *)memory_block+offset,source,size);
return(true);
}
};//class MemoryAllocator:public AbstractMemoryAllocator };//class MemoryAllocator:public AbstractMemoryAllocator
}//namespace hgl }//namespace hgl
#endif//HGL_MEMORY_ALLOCATOR_INCLUDE #endif//HGL_MEMORY_ALLOCATOR_INCLUDE