Exemplo n.º 1
0
        /// <summary> Processes realloc operation for this callstack and updates lifecycles if needed. </summary>
        public FAllocationLifecycle ProcessRealloc(FStreamToken StreamToken, ref FAllocationLifecycle NewLifecycle, FCallStack PreviousCallStack, FAllocationLifecycle PreviousLifecycle)
        {
            FAllocationLifecycle Result = null;
            int  SizeChange             = 0;
            bool bFreshRealloc          = true;

            FAllocationLifecycle Lifecycle;

            if (IncompleteLifecycles.TryGetValue(StreamToken.OldPointer, out Lifecycle))
            {
                IncompleteLifecycles.Remove(StreamToken.OldPointer);
                Lifecycle.Realloc(StreamToken, this, out SizeChange);
                if (Lifecycle.bIsComplete)
                {
                    if (FStreamInfo.GlobalInstance.CreationOptions.KeepLifecyclesCheckBox.Checked)
                    {
                        CompleteLifecycles.Add(Lifecycle);
                    }
                }
                else
                {
                    IncompleteLifecycles.Add(Lifecycle.LatestPointer, Lifecycle);
                }

                bFreshRealloc = false;
                Result        = Lifecycle;
            }
            else
            {
                Debug.Assert(NewLifecycle != null);
                NewLifecycle.Malloc(StreamToken, PreviousCallStack, PreviousLifecycle);
                Result       = NewLifecycle;
                NewLifecycle = null;

                IncompleteLifecycles.Add(Result.LatestPointer, Result);

                bFreshRealloc = true;
                SizeChange    = StreamToken.Size;
            }

            LatestSize += SizeChange;
            if (LatestSize > MaxSize)
            {
                MaxSize = LatestSize;
            }

            // it's possible that this point was already added to the graph via realloc chain propagation
            if (SizeGraphPoints != null && (SizeGraphPoints.Count == 0 || SizeGraphPoints[SizeGraphPoints.Count - 1].StreamIndex != StreamToken.StreamIndex))
            {
                SizeGraphPoints.Add(new FSizeGraphPoint(StreamToken.StreamIndex, SizeChange, bFreshRealloc));
            }

            return(Result);
        }