9 UE5 TSparseArray介绍

2024-02-26  本文已影响0人  游戏开发程序员

TSparseArray 稀疏数组

template<typename InElementType,typename Allocator /*= FDefaultSparseArrayAllocator */>
class TSparseArray
{
    using ElementType = InElementType;

    template <typename, typename>
    friend class TScriptSparseArray;
....
....

private:
    typedef TSparseArrayElementOrFreeListLink<
        TAlignedBytes<sizeof(ElementType), alignof(ElementType)>> 
FElementOrFreeListLink;

        // 数据的存储
    typedef TArray<FElementOrFreeListLink,typename Allocator::ElementAllocator> DataType;
    DataType Data;
      
        // // 索引标记存储
    typedef TBitArray<typename Allocator::BitArrayAllocator> AllocationBitArrayType;
    AllocationBitArrayType AllocationFlags;

    int32 FirstFreeIndex;

    int32 NumFreeIndices;

链表结构 TSparseArrayElementOrFreeListLink

/** Allocated elements are overlapped with free element info in the element list. */
template<typename ElementType>
union TSparseArrayElementOrFreeListLink
{
    /** If the element is allocated, its value is stored here. */
    ElementType ElementData;

    struct
    {
        /** If the element isn't allocated, this is a link to the previous element in the array's free list. */
        int32 PrevFreeIndex;

        /** If the element isn't allocated, this is a link to the next element in the array's free list. */
        int32 NextFreeIndex;
    };
};

删除图解,参考知乎

image.png

代码实操

image.png image.png
上一篇 下一篇

猜你喜欢

热点阅读