UE源码解析-TArray

这篇文章我们来分析UE里的变长数组的实现,对应模块为 Core

ContainersFwd.h 中罗列了很多容器模板的声明,里面包含 TArray

1
template<typename T, typename Allocator = FDefaultAllocator> class TArray;

Allocator

默认的分配器是 TSizedHeapAllocator ,在 ContainerAllocationPolicies.h 中声明:

1
2
template <int IndexSize> class TSizedDefaultAllocator : public TSizedHeapAllocator<IndexSize> { public: typedef TSizedHeapAllocator<IndexSize> Typedef; };
using FDefaultAllocator = TSizedDefaultAllocator<32>;