diff options
author | Boris Kirzner <borisk@mono-cvs.ximian.com> | 2004-05-19 13:46:00 +0400 |
---|---|---|
committer | Boris Kirzner <borisk@mono-cvs.ximian.com> | 2004-05-19 13:46:00 +0400 |
commit | 033e708f3c2817f3880aab072246d225848b6092 (patch) | |
tree | c24bbc3fb3d6dfbe168dc5fc9d65feb132b0617e /mcs/class/System.Data/System.Data.Common/RecordCache.cs | |
parent | 256439e2eb6e83703d6e3166c48eed386d8bbf22 (diff) |
* RecordCache.cs - added. Each instance of record cache belongs to specific table and manages pool of records ( indexes into data containers) to be used by data rows.
* DataContainer.cs - added. Provides implementation for data containers that holds data in arrays of primitives or objects. Each data container belongs to specific DataColumn.
* DbDataAdapter.cs - changes to complete data storage redesign. Bug fix in FillTable ( to fetch exact number of records required ).
svn path=/trunk/mcs/; revision=27655
Diffstat (limited to 'mcs/class/System.Data/System.Data.Common/RecordCache.cs')
-rw-r--r-- | mcs/class/System.Data/System.Data.Common/RecordCache.cs | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/mcs/class/System.Data/System.Data.Common/RecordCache.cs b/mcs/class/System.Data/System.Data.Common/RecordCache.cs new file mode 100644 index 00000000000..0cb454887c4 --- /dev/null +++ b/mcs/class/System.Data/System.Data.Common/RecordCache.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections; + +namespace System.Data.Common +{ + internal class RecordCache + { + #region Fields + + const int MIN_CACHE_SIZE = 128; + + Stack _records = new Stack(16); + int _nextFreeIndex = 0; + int _currentCapacity = 0; + DataTable _table; + + #endregion // Fields + + #region Constructors + + internal RecordCache(DataTable table) + { + _table = table; + } + + #endregion //Constructors + + #region Properties + + internal int CurrentCapacity + { + get { + return _currentCapacity; + } + } + + #endregion // Properties + + #region Methods + + internal int NewRecord() + { + if (_records.Count > 0) { + return (int)_records.Pop(); + } + else { + DataColumnCollection cols = _table.Columns; + if (_nextFreeIndex >= _currentCapacity) { + _currentCapacity *= 2; + if ( _currentCapacity < MIN_CACHE_SIZE ) { + _currentCapacity = MIN_CACHE_SIZE; + } + foreach(DataColumn col in cols) { + col.DataContainer.Capacity = _currentCapacity; + } + } + return _nextFreeIndex++; + } + } + + internal void DisposeRecord(int index) + { + if ( index < 0 ) { + throw new ArgumentException(); + } + _records.Push(index); + } + + #endregion // Methods + + } +} |