コード例 #1
0
ファイル: VTTileCache.cs プロジェクト: ttou73/IronStar
        /// <summary>
        /// Adds new page to cache.
        ///
        ///	If page exists:
        ///		- LFU index of existing page is shifted.
        ///		- returns FALSE
        ///
        /// If page with given address does not exist:
        ///		- page added to cache.
        ///		- some pages could be evicted
        ///		- return TRUE
        ///
        /// </summary>
        /// <param name="address"></param>
        /// <returns>False if page is already exist</returns>
        public bool Add(VTAddress virtualAddress, out int physicalAddress)
        {
            Page page;

            if (cache.TryGetValue(virtualAddress, out page))
            {
                physicalAddress = page.Address;

                return(false);
            }
            else
            {
                cache.Discard(out page);

                var newPage = new Page(virtualAddress, page.Address, pageCount, physTexSize);

                cache.Add(virtualAddress, newPage);

                physicalAddress = newPage.Address;

                return(true);
            }
        }