GSF.Diagnostics.Logger.GrowStackDisposal C# (CSharp) Method

GrowStackDisposal() private static method

private static GrowStackDisposal ( int desiredSize ) : void
desiredSize int
return void
        private static void GrowStackDisposal(int desiredSize)
        {
            //Since these depths are relatively small, growing them both together has minor consequence.
            lock (SyncRoot)
            {
                while (s_stackDisposalStackMessages == null || s_stackDisposalStackMessages.Length < desiredSize)
                {
                    //Note: both are grown together and completely reinitialized to improve 
                    //      locality of reference.
                    int lastSize = s_stackDisposalStackMessages?.Length ?? 2;
                    StackDisposal[] stackMessages = new StackDisposal[lastSize * 2];
                    for (int x = 0; x < stackMessages.Length; x++)
                    {
                        stackMessages[x] = new StackDisposal(x, DisposeStackMessage);
                    }
                    StackDisposal[] suppressionFlags = new StackDisposal[lastSize * 2];
                    for (int x = 0; x < suppressionFlags.Length; x++)
                    {
                        suppressionFlags[x] = new StackDisposal(x, DisposeSuppressionFlags);
                    }
                    s_stackDisposalStackMessages = stackMessages;
                    s_stackDisposalSuppressionFlags = suppressionFlags;
                }
            }
        }