예제 #1
0
파일: ContainersTest.cs 프로젝트: mo5h/omeo
        public void TestCacheEnumerator()
        {
            IntObjectCache cache = new IntObjectCache(16);

            for (int i = 0; i < 10; ++i)
            {
                cache.CacheObject(i, i);
            }
            int count = 0;

            foreach (int i in cache)
            {
                ++count;
            }
            Assert.AreEqual(10, count);
            for (int i = 0; i < 10; ++i)
            {
                cache.CacheObject(i + 10, i);
            }
            count = 0;
            foreach (int i in cache)
            {
                ++count;
            }
            Assert.AreEqual(cache.Size, count);
        }
예제 #2
0
 static IntInternalizer()
 {
     _intCacheLock = new SpinWaitLock();
     _intCache     = new IntObjectCache(_intCacheSize);
     for (int i = 0; i < _intCacheSize; ++i)
     {
         _intCache.CacheObject(i, i);
     }
 }
예제 #3
0
파일: ContainersTest.cs 프로젝트: mo5h/omeo
        public void StressCaching()
        {
            const int      cacheSize = 1000;
            IntObjectCache cache     = new IntObjectCache(cacheSize);
            Random         rnd       = new Random();

            for (int i = 0; i < 100000000; ++i)
            {
                int next = rnd.Next(cacheSize * 2);
                if (cache.TryKey(next) == null)
                {
                    cache.CacheObject(next, i);
                }
            }
            Console.WriteLine("Cache hit rate = " + cache.HitRate().ToString());
        }
예제 #4
0
파일: BlobFileSystem.cs 프로젝트: mo5h/omeo
 private void Init()
 {
     try
     {
         if (_minClusterSize != 16 && _minClusterSize != 32 && _minClusterSize != 64 && _minClusterSize != 128 && _minClusterSize != 256)
         {
             throw new ArgumentException("Minimum cluster size can only be 16, 32, 64, 128 or 256");
         }
         _maxClusterSize        = 0x10000 - _minClusterSize;
         _fragmentationStrategy = FragmentationStrategy.Quadratic;
         _reader        = new BinaryReader(_stream);
         _writer        = new BinaryWriter(_stream);
         _clusterCache  = new IntObjectCache(CLUSTER_CACHE_SIZE);
         _dirtyClusters = new IntHashSet();
         _clusterCache.ObjectRemoved += new IntObjectCacheEventHandler(_clusterCache_ObjectRemoved);
         _firstFreeFileHandle         = NOT_SET;
         _rawBytes = new byte[_minClusterSize - CLUSTER_HEADER_SIZE];
         if (_stream.Length == 0)
         {
             SaveHeader();
             _stream.SetLength(BLOB_FILE_SYSTEM_HEADER_SIZE);
         }
         else
         {
             if (_stream.Length < BLOB_FILE_SYSTEM_HEADER_SIZE || !_reader.ReadString().Equals(FS_HEADER))
             {
                 throw new IOException("Invalid file system header");
             }
             if (_reader.ReadInt32() != BLOB_FILE_SYSTEM_VERSION)
             {
                 throw new IOException("Invalid file system version");
             }
             _firstFreeFileHandle = _reader.ReadInt32();
         }
     }
     catch (Exception e)
     {
         Shutdown();
         throw e;
     }
 }
예제 #5
0
 public SingleStreamCachingStrategy(int cacheSize)
 {
     _dirtyPages = new IntHashSet();
     _pagesCache = new IntObjectCache(cacheSize >> CachedPage._pageShiftBits);
     _pagesCache.ObjectRemoved += new IntObjectCacheEventHandler(_pagesCache_ObjectRemoved);
 }