Will submit this if there is no time left to spend on the project.
+- simulator.c
This commit is contained in:
parent
d7bb439a2a
commit
240190bea4
2 changed files with 25 additions and 7 deletions
BIN
Sim03/sim03
BIN
Sim03/sim03
Binary file not shown.
|
|
@ -61,9 +61,18 @@ Device Input/Device: none
|
||||||
Device Output/Device: none
|
Device Output/Device: none
|
||||||
Dependencies: ???
|
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 (temp)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -99,8 +108,16 @@ Device Input/Device: none
|
||||||
Device Output/Device: none
|
Device Output/Device: none
|
||||||
Dependencies: ???
|
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 (temp)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -464,7 +481,7 @@ bool memManager(ProcessControlBlockLL *pcbList, MEMORY_SIGNALS memCode, int offs
|
||||||
if(size <= availableMem - usedMem + 1)
|
if(size <= availableMem - usedMem + 1)
|
||||||
{
|
{
|
||||||
// grab the offset and size, store it, using the allocate memory function.
|
// 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;
|
usedMem = usedMem + size;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -496,6 +513,7 @@ bool memManager(ProcessControlBlockLL *pcbList, MEMORY_SIGNALS memCode, int offs
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MEMORY_ACCESS:
|
case MEMORY_ACCESS:
|
||||||
|
// printf("Used memory at current: %d\n", usedMem);
|
||||||
subFunctionSuccess = accessMemory(singlePCB, offset, size);
|
subFunctionSuccess = accessMemory(singlePCB, offset, size);
|
||||||
if (memDisplay)
|
if (memDisplay)
|
||||||
{
|
{
|
||||||
|
|
@ -521,7 +539,7 @@ bool memManager(ProcessControlBlockLL *pcbList, MEMORY_SIGNALS memCode, int offs
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MEMORY_DEALLOCATE:
|
case MEMORY_DEALLOCATE:
|
||||||
subFunctionSuccess = deallocMemory(singlePCB);
|
subFunctionSuccess = deallocMemory(singlePCB, singlePCB->memArraySize);
|
||||||
if (memDisplay)
|
if (memDisplay)
|
||||||
{
|
{
|
||||||
if (subFunctionSuccess)
|
if (subFunctionSuccess)
|
||||||
|
|
@ -529,7 +547,7 @@ bool memManager(ProcessControlBlockLL *pcbList, MEMORY_SIGNALS memCode, int offs
|
||||||
// THIS SHOULD ALWAYS HAPPEN.
|
// THIS SHOULD ALWAYS HAPPEN.
|
||||||
printf("--------------------------------------------------\n");
|
printf("--------------------------------------------------\n");
|
||||||
printf("After clear process %d success\n", singlePCB->uniquePid);
|
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");
|
printf("--------------------------------------------------\n");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -537,7 +555,7 @@ bool memManager(ProcessControlBlockLL *pcbList, MEMORY_SIGNALS memCode, int offs
|
||||||
// THIS SHOULD NEVER HAPPEN.
|
// THIS SHOULD NEVER HAPPEN.
|
||||||
printf("--------------------------------------------------\n");
|
printf("--------------------------------------------------\n");
|
||||||
printf("After clear process %d failure\n", singlePCB->uniquePid);
|
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");
|
printf("--------------------------------------------------\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue