Will submit this if there is no time left to spend on the project.

+- simulator.c
This commit is contained in:
Charles Descamps 2024-03-18 22:59:27 -07:00
parent d7bb439a2a
commit 240190bea4
2 changed files with 25 additions and 7 deletions

View file

@ -61,9 +61,18 @@ Device Input/Device: none
Device Output/Device: none
Dependencies: ???
*/
bool allocMemory(ProcessControlBlock *singlePCB, int offset, int size)
bool allocMemory(ProcessControlBlock *singlePCB, int offset, int size, int arraySize)
{
// singlePCB->allocatedMemOffsets[] = offset;
int allocateIterator = 0;
// while until a '-1' is hit, then store the value.
while(singlePCB->allocatedMemSizes[allocateIterator] != -1 && allocateIterator < arraySize)
{
//
singlePCB->allocatedMemOffsets[allocateIterator] = offset;
singlePCB->allocatedMemSizes[allocateIterator] = size;
allocateIterator = allocateIterator + 1;
printf("Alloc Iter: %d\n", allocateIterator);
}
// return true (temp)
return true;
}
@ -99,8 +108,16 @@ Device Input/Device: none
Device Output/Device: none
Dependencies: ???
*/
bool deallocMemory(ProcessControlBlock *singlePCB)
bool deallocMemory(ProcessControlBlock *singlePCB, int arraySize)
{
int deallocateIterator;
// while until a '-1' is hit, then store the value.
for (deallocateIterator = 0; deallocateIterator < arraySize; deallocateIterator++)
{
//
singlePCB->allocatedMemOffsets[deallocateIterator] = -1;
singlePCB->allocatedMemSizes[deallocateIterator] = -1;
}
// return true (temp)
return true;
}
@ -464,7 +481,7 @@ bool memManager(ProcessControlBlockLL *pcbList, MEMORY_SIGNALS memCode, int offs
if(size <= availableMem - usedMem + 1)
{
// grab the offset and size, store it, using the allocate memory function.
subFunctionSuccess = allocMemory(singlePCB, offset, size);
subFunctionSuccess = allocMemory(singlePCB, offset, size, singlePCB->memArraySize);
usedMem = usedMem + size;
}
else
@ -496,6 +513,7 @@ bool memManager(ProcessControlBlockLL *pcbList, MEMORY_SIGNALS memCode, int offs
break;
case MEMORY_ACCESS:
// printf("Used memory at current: %d\n", usedMem);
subFunctionSuccess = accessMemory(singlePCB, offset, size);
if (memDisplay)
{
@ -521,7 +539,7 @@ bool memManager(ProcessControlBlockLL *pcbList, MEMORY_SIGNALS memCode, int offs
break;
case MEMORY_DEALLOCATE:
subFunctionSuccess = deallocMemory(singlePCB);
subFunctionSuccess = deallocMemory(singlePCB, singlePCB->memArraySize);
if (memDisplay)
{
if (subFunctionSuccess)
@ -529,7 +547,7 @@ bool memManager(ProcessControlBlockLL *pcbList, MEMORY_SIGNALS memCode, int offs
// THIS SHOULD ALWAYS HAPPEN.
printf("--------------------------------------------------\n");
printf("After clear process %d success\n", singlePCB->uniquePid);
printf("%d [ Open, P#: x, %d-%d ] %d\n", usedMem, currentOffset, currentSize, availableMem - 1);
printf("%d [ Open, P#: x, %d-%d ] %d\n", usedMem - usedMem, currentOffset, currentSize, availableMem - 1);
printf("--------------------------------------------------\n");
}
else
@ -537,7 +555,7 @@ bool memManager(ProcessControlBlockLL *pcbList, MEMORY_SIGNALS memCode, int offs
// THIS SHOULD NEVER HAPPEN.
printf("--------------------------------------------------\n");
printf("After clear process %d failure\n", singlePCB->uniquePid);
printf("%d [ Open, P#: x, %d-%d ] %d\n", usedMem, currentOffset, currentSize, availableMem - 1);
printf("%d [ Open, P#: x, %d-%d ] %d\n", usedMem - usedMem, currentOffset, currentSize, availableMem - 1);
printf("--------------------------------------------------\n");
}
}