Files
mono/mcs/class/System.Data/System.Data.Common/RecordCache.cs
T
Boris Kirzner 033e708f3c * 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
2004-05-19 09:46:00 +00:00

73 lines
1.2 KiB
C#

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
}
}