ASP源码.NET源码PHP源码JSP源码JAVA源码DELPHI源码PB源码VC源码VB源码Android源码
当前位置:首页 >> 软件工程 >> 给虚幻4添加内存跟踪功能

给虚幻4添加内存跟踪功能(3/6)

来源:网络整理     时间:2016-01-15     关键词:

本篇文章主要介绍了"给虚幻4添加内存跟踪功能",主要涉及到方面的内容,对于软件工程感兴趣的同学可以参考一下: 本文章由cartzhang编写,转载请注明出处。 所有权利保留。 文章链接:http://blog.csdn.net/cartzhang/article/d...

    #if USE_MALLOC_TRACKER
    void ResizeAllocation(int32 PreviousNumElements, int32 NumElements, SIZE_T NumBytesPerElement, constuint32 GroupId, constchar * const Name);
#elsevoid ResizeAllocation(int32 PreviousNumElements, int32 NumElements, SIZE_T NumBytesPerElement);
#endif // USE_MALLOC_TRACKER

同样,因为我们不想使用那个ifdefs来填充引擎的代码,我们再次使用定义来简化:

#if USE_MALLOC_TRACKER#define PZ_CONTAINER_RESIZE_ALLOCATION(ContainerPtr, PreviousNumElements, NumElements, NumBytesPerElement, GroupId, Name) (ContainerPtr)->ResizeAllocation((PreviousNumElements), (NumElements), (NumBytesPerElement), (GroupId), (Name))#else#define PZ_CONTAINER_RESIZE_ALLOCATION(ContainerPtr, PreviousNumElements, NumElements, NumBytesPerElement, GroupId, Name) (ContainerPtr)->ResizeAllocation((PreviousNumElements), (NumElements), (NumBytesPerElement))#endif // USE_MALLOC_TRACKER

这样,我们可以把ArrayName和ArrayGroup传递给容器分配器。
在构造之后,还有一个需要修改容器的名称或分组,因为给容器的容器命名分配器是非常有必要的。其中的一个例子就是,在任一TMap容器中FindOrAdd后,我们需要设置名称或分组。

/** Map of object to their outers, used to avoid an object iterator to find such things. **/
TMap > ObjectOuterMap;
TMap > ClassToObjectListMap;
TMap > ClassToChildListMap;

这样以来,所有的容器内存分配器有了标签属性。现在,我们需要的是给容器设置名称。以FMeshParticleVertexFactory::DataType::TextureCoordinates为例,我们可以设置它的名称和分组:

DataType()
    : TextureCoordinates(GROUP_RENDERING, "FMeshParticleVertexFactory::DataType::TextureCoordinates")
    , bInitialized(false)
{
}

定义作用域

作为“内存申请和跟踪”博客中一部分,为提供上下文链接,我提及到内存分配定义作用域的必要性。这个作用域与调用栈(它已经由MallocProfiler提供)不一样。很多分配在同一栈中,但是涉及到完全不同的对象。在使用蓝图过程中更是普遍。正是由于这个,作用域在跟踪或甚至带蓝图的内存使用都是非常有用的。

相关图片

相关文章