Beispiel #1
0
 public void FreeMemory()
 {
     lock (_lock)
     {
         _bits.Optimize();
         SaveIndex();
     }
 }
        private void WriteFreeListBMPFile()
        {
            // write freelist to end of blocks and update master block
            if (_freeList != null)
            {
                _freeList.Optimize();
                var o = _freeList.Serialize();
                var b = fastBinaryJSON.BJSON.ToBJSON(o, new fastBinaryJSON.BJSONParameters {
                    UseExtensions = false
                });

                var len    = b.Length;
                var offset = 0;
                // write master block
                SeekBlock(0);
                _lastBlockNumber++;
                WriteBlockBytes(new byte[] { (byte)'F', (byte)'L' }, 0, 2);
                WriteBlockBytes(Helper.GetBytes(_lastBlockNumber, false), 0, 4);
                WriteBlockBytes(Helper.GetBytes(len, false), 0, 4);
                // seek to end of file
                SeekBlock(_lastBlockNumber);
                while (len > 0)
                {
                    WriteBlockBytes(new byte[] { (byte)'F', (byte)'L' }, 0, 2);
                    WriteBlockBytes(b, offset, len > _BLOCKSIZE ? _BLOCKSIZE - 2 : len);
                    len -= (_BLOCKSIZE - 2);
                }
            }
        }
Beispiel #3
0
        public void Commit(bool freeMemory)
        {
            if (_isDirty == false)
            {
                return;
            }
            using (new L(this))
            {
                log.Debug("writing " + _filename);

                int[] keys = _cache.Keys();
                Array.Sort(keys);

                foreach (int k in keys)
                {
                    MGRB bmp = null;
                    if (_cache.TryGetValue(k, out bmp) && bmp.isDirty)
                    {
                        bmp.Optimize();
                        SaveBitmap(k, bmp);
                        bmp.isDirty = false;
                    }
                }
                Flush();
                if (freeMemory)
                {
                    if (Global.UseLessMemoryStructures)
                    {
                        _cache = new SafeSortedList <int, MGRB>();
                    }
                    else
                    {
                        _cache = new SafeDictionary <int, MGRB>();
                    }
                    log.Debug("  freeing cache");
                }
                _isDirty = false;
            }
        }