diff --git a/Sim03/sim03 b/Sim03/sim03 index b426ccf..393e6ba 100755 Binary files a/Sim03/sim03 and b/Sim03/sim03 differ diff --git a/Sim03/simulator.c b/Sim03/simulator.c index 1583ecb..5699961 100644 --- a/Sim03/simulator.c +++ b/Sim03/simulator.c @@ -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"); } }