예제 #1
0
        /// <summary>
        /// Free method declaration.
        /// This method marks space in the database file as free.
        /// </summary>
        /// <remarks>
        /// If more than MAX_FREE_COUNT free positios then
        /// they are probably all are too small anyway; so we start a new list.
        /// TODO: This is wrong when deleting lots of records.
        /// </remarks>
        ///
        /// <param name="row">Row object to be marked free</param>
        /// <param name="pos">Offset in the file this Row was stored at</param>
        /// <param name="length">Size of the Row object to free</param>
        public void Free(Row row, int pos, int length)
        {
            _freeCount++;

            CacheFree n = new CacheFree();

            n.Pos    = pos;
            n.Length = length;

            if (_freeCount > MAX_FREE_COUNT)
            {
                _freeCount = 0;
            }
            else
            {
                n.Next = _cacheRoot;
            }

            _cacheRoot = n;

            // it's possible to remove roots to
            Remove(row);
        }
예제 #2
0
        /// <summary>
        /// Add method declaration.
        /// This method adds a Row to the Cache.  It walks the
        /// list of CacheFree objects to see if there is available space
        /// to store the new Row, reusing space if it exists, otherwise
        /// we grow the file.
        /// </summary>
        /// <param name="row">Row to be added to Cache</param>
        public void Add(Row row)
        {
            int       size = row.Size;
            CacheFree f    = _cacheRoot;
            CacheFree last = null;
            int       i    = _freePos;

            while (f != null)
            {
                if (TracingHelper.TraceEnabled)
                {
                    TracingHelper.Stop();
                }
                // first that is long enough
                if (f.Length >= size)
                {
                    i    = f.Pos;
                    size = f.Length - size;

                    if (size < 8)
                    {
                        // remove almost empty blocks
                        if (last == null)
                        {
                            _cacheRoot = f.Next;
                        }
                        else
                        {
                            last.Next = f.Next;
                        }

                        _freeCount--;
                    }
                    else
                    {
                        f.Length = size;
                        f.Pos   += row.Size;
                    }

                    break;
                }

                last = f;
                f    = f.Next;
            }

            row.Pos = i;

            if (i == _freePos)
            {
                _freePos += size;
            }

            int k      = i & MASK;
            Row before = _rowData[k];

            if (before == null)
            {
                before = _rowFirst;
            }

            row.Insert(before);

            _cacheSize++;
            _rowData[k] = row;
            _rowFirst   = row;
        }
예제 #3
0
파일: Cache.cs 프로젝트: furesoft/SharpHSQL
        /// <summary>
        /// Free method declaration.
        /// This method marks space in the database file as free.
        /// </summary>
        /// <remarks>
        /// If more than MAX_FREE_COUNT free positios then
        /// they are probably all are too small anyway; so we start a new list.
        /// TODO: This is wrong when deleting lots of records.
        /// </remarks>
        /// 
        /// <param name="row">Row object to be marked free</param>
        /// <param name="pos">Offset in the file this Row was stored at</param>
        /// <param name="length">Size of the Row object to free</param>
        public void Free(Row row, int pos, int length)
        {
            _freeCount++;

            CacheFree n = new CacheFree();

            n.Pos = pos;
            n.Length = length;

            if (_freeCount > MAX_FREE_COUNT)
                _freeCount = 0;
            else
                n.Next = _cacheRoot;

            _cacheRoot = n;

            // it's possible to remove roots to
            Remove(row);
        }
예제 #4
0
파일: Cache.cs 프로젝트: furesoft/SharpHSQL
        /// <summary>
        /// Add method declaration.
        /// This method adds a Row to the Cache.  It walks the
        /// list of CacheFree objects to see if there is available space
        /// to store the new Row, reusing space if it exists, otherwise
        /// we grow the file.
        /// </summary>
        /// <param name="row">Row to be added to Cache</param>
        public void Add(Row row)
        {
            int       size = row.Size;
            CacheFree f = _cacheRoot;
            CacheFree last = null;
            int       i = _freePos;

            while (f != null)
            {
                if (TracingHelper.TraceEnabled)
                {
                    TracingHelper.Stop();
                }
                // first that is long enough
                if (f.Length >= size)
                {
                    i = f.Pos;
                    size = f.Length - size;

                    if (size < 8)
                    {
                        // remove almost empty blocks
                        if (last == null)
                        {
                            _cacheRoot = f.Next;
                        }
                        else
                        {
                            last.Next = f.Next;
                        }

                        _freeCount--;
                    }
                    else
                    {
                        f.Length = size;
                        f.Pos += row.Size;
                    }

                    break;
                }

                last = f;
                f = f.Next;
            }

            row.Pos = i;

            if (i == _freePos)
            {
                _freePos += size;
            }

            int k = i & MASK;
            Row before = _rowData[k];

            if (before == null)
            {
                before = _rowFirst;
            }

            row.Insert(before);

            _cacheSize++;
            _rowData[k] = row;
            _rowFirst = row;
        }