update 0927

This commit is contained in:
codeboss 2025-09-27 23:04:35 +08:00
parent 6d6df7fa83
commit b1705db60f
2 changed files with 77 additions and 2 deletions

View File

@ -3,3 +3,57 @@
ECSMemoryPool::ECSMemoryPool()
{
}
ChunkAccessIndex::ChunkAccessIndex(ElementControlBlock* ecb, uint64_t chunk_type_code)
:_element_bind(MemoryElement(ecb)), _chunk_type_code(chunk_type_code)
{
}
ChunkAccessIndex::ChunkAccessIndex(const ChunkAccessIndex& other) :_element_bind(other._element_bind),
_chunk_type_code(other._chunk_type_code),
_member_offset(other._member_offset)
{
}
uint64_t ChunkAccessIndex::chunkType() const
{
return _chunk_type_code;
}
uint16_t ChunkAccessIndex::chunkSize() const
{
return _element_bind.typeSize();
}
bool ChunkAccessIndex::contains(uint64_t type_code)
{
return _member_offset.find(type_code) != _member_offset.cend();
}
int8_t ChunkAccessIndex::setMember(uint64_t type_code, uint16_t offset, uint16_t size)
{
if (_element_bind.typeSize() <= offset + size) {
return -1;
}
_member_offset[type_code] = std::make_pair(offset, size);
return 0;
}
unsigned char* ChunkAccessIndex::getLockedDataPtr(uint64_t type_code)
{
auto index_offset = _member_offset.find(type_code);
if (index_offset == _member_offset.cend())
return nullptr;
auto raw_ptr = _element_bind.dataLock();
auto data_target_ptr = raw_ptr + index_offset->first;
return data_target_ptr;
}
void ChunkAccessIndex::releaseData()
{
_element_bind.release();
}

View File

@ -4,6 +4,7 @@
#include <QJsonObject>
#include <QList>
#include <QHash>
#include <map>
#include <memory_pages.h>
template<typename T>
@ -34,6 +35,26 @@ public:
};
class ECSMEMORYPOOL_EXPORT ChunkAccessIndex {
private:
MemoryElement _element_bind;
uint64_t _chunk_type_code;
std::map<uint64_t, std::pair<uint16_t, uint16_t>> _member_offset;
public:
ChunkAccessIndex(ElementControlBlock* ecb, uint64_t chunk_type_code);
ChunkAccessIndex(const ChunkAccessIndex& other);
uint64_t chunkType() const;
uint16_t chunkSize() const;
bool contains(uint64_t type_code);
int8_t setMember(uint64_t type_code, uint16_t offset, uint16_t size);
unsigned char* getLockedDataPtr(uint64_t type_code);
void releaseData();
};
class ECSMEMORYPOOL_EXPORT ECSMemoryPool {
private:
std::mutex _pool_protected_;