::SHE+ILA:: Source Code Continued (20250319.1)

Woman in Purple Velvet Dress in Elegant Room
163
1
  • Squishy Plushie's avatar Artist
    Squishy Pl...
  • Prompt
    Read prompt
  • DDG Model
    DaVinci2
  • Access
    Public
  • Created
    1d ago
  • Try

More about ::SHE+ILA:: Source Code Continued (20250319.1)

We have just discussed class PageFrame. Now we discuss the ::SHE:: module itself. It is the "datastore" or "virtual memory manager" of the ::SHE+ILA:: operating system :)
We have three globals interfacing ::SHE:: to class PageFrame, as shown in the description of the previous drawing.
They are g_FrameCount, g_SwapLBA, and g_LRUhead. Normally globals are a bad thing, but here they simplify usage of the PageFrame class.
class SHE_MMU {
PageFrame* PageTable[MAX_PAGES]; // MAX_PAGES could typically be 32768 for a 1 gigabyte system. (32768*32768==1GB)
handle m_h;
public:
SHE_MMU() {
zeroise(&PageTable, sizeof (PageTable)); // Mark all pages absent
m_h = FILE_OPEN(L"SHEILASTORE.SYS"); // Permanently open our "swapfile"
for (int i=0; i<10; i++) PageTable[i] = new PageFrame(m_h, i); // Swap in SYSLIB at bootup
}
~SHE_MMU() {
for (int i=0; i<MAX_PAGES) if (PageTable[i]) delete PageTable[i]; // Checkpoint everything on shutdown
FILE_CLOSE(m_h);
}
PageFrame* operator()(int lba) { // Fetch a page
if PageTable[lba] return PageTable[lba] // It's resident
else // We must swap it in
// If FrameCount is exceeded then swap out the least recently used (LRU) page
if (g_FrameCount > MAX_FRAMES) { // Adjust MAX_FRAMES to suit your machine's available RAM
delete PageTable[g_SwapLBA];
PageTable[g_SwapLBA] = NULL;
}
PageTable[lba] = new PageFrame(m_h, lba);
ASSERT(PageTable[lba] != NULL);
return PageTable[lba];
}
}; // MORE TO FOLLOW...

Comments


Loading Dream Comments...

Discover more dreams from this artist