コード例 #1
0
ファイル: memSegmentManager.cs プロジェクト: luanzhu/OOD.NET
        private FileHeader m_fileHeader;                               //the only file header in the two files, it is located at page 0.

        public memSegmentManager(DiskFile file)
        {
            m_cache = new CacheHashtable(m_cacheSize);

            m_pageSize   = 1 << m_pageBits;
            m_diskFile   = file;
            m_bitmap     = new PageBitmap();
            m_fileHeader = new FileHeader();
            if (file.Length < m_bitmap.Data.Length + m_pageSize * 2)           //page 0 for fileheader, page 33 for segTree, page 44 for spacetree
            {
                //this helper file is a new one

                for (int i = 0; i < (m_bitmap.Data.Length >> (m_pageBits + 3)); i++)
                {
                    m_bitmap.Data[i] = 0xFF;
                }
                m_bitmap.SetPageTaken(m_bitmap.GetFirstFreePageID());                 //one more page taken because of the fileheader
                m_bitmap.Dirty = true;

                m_fileHeader.SetInitializeNeeded();
            }
            else
            {
                byte[] header = file.SynRead(0, m_pageSize);
                m_fileHeader.Deserialize(header);
                file.SynRead(m_bitmap.Data, 0, m_pageSize, m_bitmap.Data.Length);
            }

            m_LRU = new BNode();
        }
コード例 #2
0
ファイル: memSegmentManager.cs プロジェクト: luanzhu/OOD.NET
		private			FileHeader		m_fileHeader; //the only file header in the two files, it is located at page 0.
		
		public memSegmentManager(DiskFile file)
		{
			m_cache = new CacheHashtable(m_cacheSize);

			m_pageSize = 1 << m_pageBits;
			m_diskFile = file;
			m_bitmap = new PageBitmap();
			m_fileHeader = new FileHeader();
			if (file.Length < m_bitmap.Data.Length + m_pageSize*2) //page 0 for fileheader, page 33 for segTree, page 44 for spacetree
			{
				//this helper file is a new one

				for (int i=0; i<(m_bitmap.Data.Length >> (m_pageBits + 3)); i++)
					m_bitmap.Data[i] = 0xFF;
				m_bitmap.SetPageTaken(m_bitmap.GetFirstFreePageID()); //one more page taken because of the fileheader
				m_bitmap.Dirty = true;

				m_fileHeader.SetInitializeNeeded();
			}
			else 
			{
				byte[] header = file.SynRead(0, m_pageSize);
				m_fileHeader.Deserialize(header);
				file.SynRead(m_bitmap.Data, 0, m_pageSize, m_bitmap.Data.Length);
			}

			m_LRU = new BNode();
		}
コード例 #3
0
ファイル: memSegmentManager.cs プロジェクト: luanzhu/OOD.NET
        public override Segment GetSegment(uint segId, Segment segFactory, object helper)
        {
            Debug.Assert(segId >= (m_bitmap.Data.Length >> m_pageBits));
            Debug.Assert(m_bitmap.PageFree(segId) == false);

            if (m_cache.Exists(segId))
            {
                //requested page is in the cache
                Segment seg = m_cache.Retrive(segId);
                //update recently used page list, move this one to the front of the list, most recently used.
                seg.BreakLinks();
                seg.BuildLinks(m_LRU, m_LRU.Next);

                return(seg);
            }
            else
            {
                //the requested page is not in the cache, read it from disk
                byte[]  content = m_diskFile.SynRead(segId * m_pageSize, m_pageSize);
                Segment seg     = segFactory.Deserialize(segId, helper, content);

                _put_in_cache(seg);

                return(seg);
            }
        }
コード例 #4
0
        public override Segment GetSegment(uint segId, Segment segFactory, object helper)
        {
            Segment result = null;

            //check if this segment is already in cache
            if (m_cache.Exists(segId))
            {
                result = m_cache.Retrive(segId);

                //update the least recently used list
                result.BreakLinks();
                result.BuildLinks(m_LRU, m_LRU.Next);

                return(result);
            }
            else
            {
                //if not, read that from disk
                uint offset = 0;
                int  length = 0;
                if (m_segTree.GetAddr(segId, ref offset, ref length))
                {
                    // put this segment into cache
                    byte[] content = m_diskFile.SynRead(offset, length);
                    result = segFactory.Deserialize(segId, helper, content);

                    _put_in_cache(result);
                }
                else
                {
                    throw new OOD.Exception.ProgramLogicError(
                              this,
                              "Trying to access a non-existing segment.");
                }
                return(result);
            }
        }