Exemple #1
0
        public void InsertPage(Page pageToInsert)
        {
            lock (_object)
            {
                for (int i = 0; i < _sizeOfVirtualMemory; ++i)
                {
                    if (_pages[i] == null)
                    {
                        _pages[i] = pageToInsert;
                        VirtualMemoryUpdatedEvent?.Invoke(i, pageToInsert.ProcessID, pageToInsert.PageNumber);

                        return;
                    }
                }

                throw new OutOfMemoryException();
            }
        }
Exemple #2
0
        public Page ExtractPage(int processID, int pageNumber)
        {
            lock (_object)
            {
                for (int i = 0; i < _sizeOfVirtualMemory; ++i)
                {
                    if (_pages[i] != null && _pages[i].ProcessID == processID && _pages[i].PageNumber == pageNumber)
                    {
                        Page resPage = _pages[i];
                        _pages[i] = null;

                        VirtualMemoryUpdatedEvent?.Invoke(i, -1, -1);

                        return(resPage);
                    }
                }

                return(null);
            }
        }