From: Wraith2 Date: Tue, 9 Apr 2019 20:19:29 +0000 (+0100) Subject: remove pool X-Git-Tag: submit/tizen/20210909.063632~11031^2~1911^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=32daacbaf948112b5dc193cedebedc01c32d7b43;p=platform%2Fupstream%2Fdotnet%2Fruntime.git remove pool Commit migrated from https://github.com/dotnet/corefx/commit/538cf16de9aa7155d6b905272648f3d9a3492cb0 --- diff --git a/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/TdsParser.cs b/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/TdsParser.cs index 8e07c39..2c35b0d 100644 --- a/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/TdsParser.cs +++ b/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/TdsParser.cs @@ -1937,7 +1937,7 @@ namespace System.Data.SqlClient } SqlEnvChange head = env; env = env.Next; - SqlEnvChangePool.Release(head); + head.Clear(); head = null; } break; @@ -2187,7 +2187,7 @@ namespace System.Data.SqlClient while (tokenLength > processedLength) { - SqlEnvChange env = SqlEnvChangePool.Allocate(); + var env = new SqlEnvChange(); if (!stateObj.TryReadByte(out env.type)) { diff --git a/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/TdsParserHelperClasses.cs b/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/TdsParserHelperClasses.cs index ef8a0fa..96e1895 100644 --- a/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/TdsParserHelperClasses.cs +++ b/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/TdsParserHelperClasses.cs @@ -298,59 +298,6 @@ namespace System.Data.SqlClient } } - /// - /// this class implements a static pool of SqlEnvChange objects to help reduce memory churn in low resource - /// situations. For low frequency querying behaviour most env change objects will be sourced and returned - /// to the pool. In higher frequency situations the pool will create and discard any additional objects that - /// are needed without blocking the caller so that it doesn't become a bottleneck, overall memory consumption - /// should still be lower than without the pool - /// - internal static class SqlEnvChangePool - { - // the conatiner struct allows avoidance of array variance checks on assignment - private protected struct SqlEnvChangeContainer - { - public SqlEnvChange Item; - } - - private static readonly SqlEnvChangeContainer[] _items = new SqlEnvChangeContainer[Environment.ProcessorCount * 2]; - - internal static SqlEnvChange Allocate() - { - SqlEnvChangeContainer[] items = _items; - for (int index = 0; index < items.Length; index++) - { - SqlEnvChange item = items[index].Item; - if (item != null && Interlocked.CompareExchange(ref items[index].Item, null, item) == item) - { - return item; - } - } - // if we didn't find an item in the pool we've either never create any or we're under pressure - // so just create a new one and let the caller get on with their work - return new SqlEnvChange(); - } - - internal static void Release(SqlEnvChange item) - { - if (item is null) - { - Debug.Fail("attempting to release null item"); - return; - } - item.Clear(); - SqlEnvChangeContainer[] items = _items; - for (int index = 0; index < items.Length; index++) - { - if (Interlocked.CompareExchange(ref items[index].Item, item, null) is null) - { - break; - } - } - // if we didn't add the item to the cache just let it go to the GC - } - } - internal sealed class SqlLogin { internal int timeout; // login timeout