diff --git a/Assignment6/.gitignore b/Assignment6/.gitignore new file mode 100644 index 0000000..0a0d96b --- /dev/null +++ b/Assignment6/.gitignore @@ -0,0 +1,5 @@ +# Built program +program1 + +# Testing output +student_out/* \ No newline at end of file diff --git a/Assignment6/.idea/.gitignore b/Assignment6/.idea/.gitignore new file mode 100644 index 0000000..1c2fda5 --- /dev/null +++ b/Assignment6/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/Assignment6/.idea/misc.xml b/Assignment6/.idea/misc.xml new file mode 100644 index 0000000..0f700bb --- /dev/null +++ b/Assignment6/.idea/misc.xml @@ -0,0 +1,20 @@ + + + + + + + + \ No newline at end of file diff --git a/Assignment6/.idea/runConfigurations/all.xml b/Assignment6/.idea/runConfigurations/all.xml new file mode 100644 index 0000000..38b79f9 --- /dev/null +++ b/Assignment6/.idea/runConfigurations/all.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Assignment6/.idea/runConfigurations/build.xml b/Assignment6/.idea/runConfigurations/build.xml new file mode 100644 index 0000000..fb2c672 --- /dev/null +++ b/Assignment6/.idea/runConfigurations/build.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Assignment6/.idea/runConfigurations/clean.xml b/Assignment6/.idea/runConfigurations/clean.xml new file mode 100644 index 0000000..12476b0 --- /dev/null +++ b/Assignment6/.idea/runConfigurations/clean.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Assignment6/.idea/runConfigurations/test.xml b/Assignment6/.idea/runConfigurations/test.xml new file mode 100644 index 0000000..d8d588b --- /dev/null +++ b/Assignment6/.idea/runConfigurations/test.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Assignment6/.idea/vcs.xml b/Assignment6/.idea/vcs.xml new file mode 100644 index 0000000..2e3f692 --- /dev/null +++ b/Assignment6/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Assignment6/Makefile b/Assignment6/Makefile new file mode 100644 index 0000000..5e46e89 --- /dev/null +++ b/Assignment6/Makefile @@ -0,0 +1,41 @@ +.PHONY: clean build test 1 2 3 4 5 6 7 8 9 10 11 12 13 14 + +all: clean build test + +test: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 + +clean: + rm -rf ./program1 + rm -rf student_out/* + +build: + gcc -g -O0 ./code/*.c -o program1 + +1: + ./program1 -s 10 -f < ./in/test1.in > ./student_out/test1-a.out && diff ./student_out/test1-a.out ./out/test1.out +2: + ./program1 -s 10 -f < ./in/test2.in > ./student_out/test2-a.out && diff ./student_out/test2-a.out ./out/test2.out +3: + ./program1 -s 10 -f < ./in/test3.in > ./student_out/test3-a.out && diff ./student_out/test3-a.out ./out/test3.out +4: + ./program1 -s 10 -f < ./in/test4.in > ./student_out/test4-a.out && diff ./student_out/test4-a.out ./out/test4.out +5: + ./program1 -s 10 -f < ./in/test5.in > ./student_out/test5-a.out && diff ./student_out/test5-a.out ./out/test5.out +6: + ./program1 -s 10 -f < ./in/test6.in > ./student_out/test6-a.out && diff ./student_out/test6-a.out ./out/test6.out +7: + ./program1 -s 5 -f < ./in/test7.in > ./student_out/test7-a.out && diff ./student_out/test7-a.out ./out/test7-a.out +8: + ./program1 -s 5 -b < ./in/test7.in > ./student_out/test7-b.out && diff ./student_out/test7-b.out ./out/test7-b.out +9: + ./program1 -s 5 -w < ./in/test7.in > ./student_out/test7-c.out && diff ./student_out/test7-c.out ./out/test7-c.out +10: + ./program1 -s 5 -f < ./in/test8.in > ./student_out/test8-a.out && diff ./student_out/test8-a.out ./out/test8-a.out +11: + ./program1 -s 5 -b < ./in/test8.in > ./student_out/test8-b.out && diff ./student_out/test8-b.out ./out/test8-b.out +12: + ./program1 -s 5 -w < ./in/test8.in > ./student_out/test8-c.out && diff ./student_out/test8-c.out ./out/test8-c.out +13: + ./program1 -s 5 -w < ./in/test9.in > ./student_out/test13.out && diff ./student_out/test13.out ./out/test13.out +14: + ./program1 -s 103 -f < ./in/test10.in > ./student_out/test14.out && diff ./student_out/test14.out ./out/test14.out diff --git a/Assignment6/code/starter_code.c b/Assignment6/code/starter_code.c new file mode 100644 index 0000000..322d815 --- /dev/null +++ b/Assignment6/code/starter_code.c @@ -0,0 +1,102 @@ +#include +#include +#include + +// 1 - best fit +// 2 - worst fit +// 3 - first fit +enum Algorithm { + BEST_FIT = 1, + WORST_FIT = 2, + FIRST_FIT = 3 +}; +int algorithm; +int memSize; +int totalAllocated = 0; +int totalMemAllocated = 0; +int totalFailed = 0; +int totalTerminated = 0; +int totalFreedMemory = 0; + + +int doFree(int processId) { + return 0; +} + + +int doAllocate(int howMuchToAllocate, int processId) { + + switch (algorithm) { + case 1: { + break; + } + case 2: { + break; + } + case 3: { + break; + } + default: { + printf("There was an error, the algorithm is uninitialized"); + exit(0); + } + } +} + +int calcFinalMemory() { + return 0; +} + +int getNumberOfChunks() { + return 0; +} + +int getSmallest() { + return 0; +} + +int getBiggest() { + return 0; +} + +int main(int argc, char **argv) { + int i = 0; + for (i = 0; i < argc; i++) { + if (strcmp(argv[i], "-b") == 0) { + algorithm = 1; + } else if (strcmp(argv[i], "-w") == 0) { + algorithm = 2; + } else if (strcmp(argv[i], "-s") == 0) { + memSize = atoi(argv[i + 1]); + } else if (strcmp(argv[i], "-f") == 0) { + algorithm = 3; + } + } + if (memSize >= 0) { + // initialize your memory here + } else { + printf("The program requires size\n"); + exit(0); + } + char operation; + int id = 1337; + int size; + while (EOF != scanf("%c", &operation)) { + switch (operation) { + case 'N': + scanf(" %d %d\n", &id, &size); + doAllocate(size, id); + break; + case 'T': + scanf(" %d\n", &id); + doFree(id); + break; + case 'S': + printf("Total Processes created %d, Total allocated memory %d, Total Processes\nterminated %d, Total freed memory %d, Final memory available %d, Final\nsmallest and largest fragmented memory sizes %d and %d, total failed requests:%d, number of memory chunks: %d\n", + totalAllocated, totalMemAllocated, totalTerminated, totalFreedMemory, calcFinalMemory(), getSmallest(), getBiggest(), totalFailed, + getNumberOfChunks()); + break; + } + } + return 0; +} \ No newline at end of file diff --git a/Assignment6/documentation/Assignment 6-v2.pdf b/Assignment6/documentation/Assignment 6-v2.pdf new file mode 100644 index 0000000..e6169a2 Binary files /dev/null and b/Assignment6/documentation/Assignment 6-v2.pdf differ diff --git a/Assignment6/documentation/sample_test_suite-2023.zip b/Assignment6/documentation/sample_test_suite-2023.zip new file mode 100644 index 0000000..3038588 Binary files /dev/null and b/Assignment6/documentation/sample_test_suite-2023.zip differ diff --git a/Assignment6/in/test1.in b/Assignment6/in/test1.in new file mode 100644 index 0000000..c428f30 --- /dev/null +++ b/Assignment6/in/test1.in @@ -0,0 +1,2 @@ +N 1 5 +S diff --git a/Assignment6/in/test10.in b/Assignment6/in/test10.in new file mode 100644 index 0000000..9c947d7 --- /dev/null +++ b/Assignment6/in/test10.in @@ -0,0 +1,102 @@ +N 1 1 +N 2 1 +N 3 1 +N 4 1 +N 5 1 +N 6 1 +N 7 1 +N 8 1 +N 9 1 +N 10 1 +N 11 1 +N 12 1 +N 13 1 +N 14 1 +N 15 1 +N 16 1 +N 17 1 +N 18 1 +N 19 1 +N 20 1 +N 21 1 +N 22 1 +N 23 1 +N 24 1 +N 25 1 +N 26 1 +N 27 1 +N 28 1 +N 29 1 +N 30 1 +N 31 1 +N 32 1 +N 33 1 +N 34 1 +N 35 1 +N 36 1 +N 37 1 +N 38 1 +N 39 1 +N 40 1 +N 41 1 +N 42 1 +N 43 1 +N 44 1 +N 45 1 +N 46 1 +N 47 1 +N 48 1 +N 49 1 +N 50 1 +N 51 1 +N 52 1 +N 53 1 +N 54 1 +N 55 1 +N 56 1 +N 57 1 +N 58 1 +N 59 1 +N 60 1 +N 61 1 +N 62 1 +N 63 1 +N 64 1 +N 65 1 +N 66 1 +N 67 1 +N 68 1 +N 69 1 +N 70 1 +N 71 1 +N 72 1 +N 73 1 +N 74 1 +N 75 1 +N 76 1 +N 77 1 +N 78 1 +N 79 1 +N 80 1 +N 81 1 +N 82 1 +N 83 1 +N 84 1 +N 85 1 +N 86 1 +N 87 1 +N 88 1 +N 89 1 +N 90 1 +N 91 1 +N 92 1 +N 93 1 +N 94 1 +N 95 1 +N 96 1 +N 97 1 +N 98 1 +N 99 1 +N 100 1 +N 101 1 +S diff --git a/Assignment6/in/test2.in b/Assignment6/in/test2.in new file mode 100644 index 0000000..92cf858 --- /dev/null +++ b/Assignment6/in/test2.in @@ -0,0 +1,3 @@ +N 1 5 +T 1 +S diff --git a/Assignment6/in/test3.in b/Assignment6/in/test3.in new file mode 100644 index 0000000..38b6033 --- /dev/null +++ b/Assignment6/in/test3.in @@ -0,0 +1,4 @@ +N 1 5 +N 2 5 +N 3 5 +S diff --git a/Assignment6/in/test4.in b/Assignment6/in/test4.in new file mode 100644 index 0000000..64d3218 --- /dev/null +++ b/Assignment6/in/test4.in @@ -0,0 +1,3 @@ +N 1 5 +T 7 5 +S diff --git a/Assignment6/in/test5.in b/Assignment6/in/test5.in new file mode 100644 index 0000000..ac330a5 --- /dev/null +++ b/Assignment6/in/test5.in @@ -0,0 +1,5 @@ +N 1 5 +N 2 5 +N 3 5 +T 3 +S diff --git a/Assignment6/in/test6.in b/Assignment6/in/test6.in new file mode 100644 index 0000000..6323b5e --- /dev/null +++ b/Assignment6/in/test6.in @@ -0,0 +1,6 @@ +N 1 5 +N 2 5 +T 2 +T 1 +N 1 3 +S diff --git a/Assignment6/in/test7.in b/Assignment6/in/test7.in new file mode 100644 index 0000000..6e3f94c --- /dev/null +++ b/Assignment6/in/test7.in @@ -0,0 +1,8 @@ +N 1 1 +N 2 1 +N 3 1 +N 4 1 +T 2 +T 1 +N 5 1 +S diff --git a/Assignment6/in/test8.in b/Assignment6/in/test8.in new file mode 100644 index 0000000..da66176 --- /dev/null +++ b/Assignment6/in/test8.in @@ -0,0 +1,8 @@ +N 1 1 +N 2 1 +N 3 1 +N 4 1 +T 2 +T 4 +N 5 1 +S diff --git a/Assignment6/in/test9.in b/Assignment6/in/test9.in new file mode 100644 index 0000000..f484460 --- /dev/null +++ b/Assignment6/in/test9.in @@ -0,0 +1,9 @@ +N 1 1 +N 2 1 +N 3 1 +N 4 1 +T 4 +T 2 +N 5 1 +T 5 +S diff --git a/Assignment6/out/test1.out b/Assignment6/out/test1.out new file mode 100644 index 0000000..324007f --- /dev/null +++ b/Assignment6/out/test1.out @@ -0,0 +1,3 @@ +Total Processes created 1, Total allocated memory 5, Total Processes +terminated 0, Total freed memory 0, Final memory available 5, Final +smallest and largest fragmented memory sizes 5 and 5, total failed requests:0, number of memory chunks: 1 diff --git a/Assignment6/out/test13.out b/Assignment6/out/test13.out new file mode 100644 index 0000000..bd36fc3 --- /dev/null +++ b/Assignment6/out/test13.out @@ -0,0 +1,3 @@ +Total Processes created 5, Total allocated memory 5, Total Processes +terminated 3, Total freed memory 3, Final memory available 3, Final +smallest and largest fragmented memory sizes 1 and 2, total failed requests:0, number of memory chunks: 2 diff --git a/Assignment6/out/test14.out b/Assignment6/out/test14.out new file mode 100644 index 0000000..3f366c0 --- /dev/null +++ b/Assignment6/out/test14.out @@ -0,0 +1,3 @@ +Total Processes created 101, Total allocated memory 101, Total Processes +terminated 0, Total freed memory 0, Final memory available 2, Final +smallest and largest fragmented memory sizes 2 and 2, total failed requests:0, number of memory chunks: 1 diff --git a/Assignment6/out/test2.out b/Assignment6/out/test2.out new file mode 100644 index 0000000..7eb8c3a --- /dev/null +++ b/Assignment6/out/test2.out @@ -0,0 +1,3 @@ +Total Processes created 1, Total allocated memory 5, Total Processes +terminated 1, Total freed memory 5, Final memory available 10, Final +smallest and largest fragmented memory sizes 10 and 10, total failed requests:0, number of memory chunks: 1 diff --git a/Assignment6/out/test3.out b/Assignment6/out/test3.out new file mode 100644 index 0000000..1622095 --- /dev/null +++ b/Assignment6/out/test3.out @@ -0,0 +1,4 @@ +Process 3 failed to allocate 5 memory +Total Processes created 2, Total allocated memory 10, Total Processes +terminated 0, Total freed memory 0, Final memory available 0, Final +smallest and largest fragmented memory sizes 0 and 0, total failed requests:1, number of memory chunks: 0 diff --git a/Assignment6/out/test4.out b/Assignment6/out/test4.out new file mode 100644 index 0000000..592ea04 --- /dev/null +++ b/Assignment6/out/test4.out @@ -0,0 +1,4 @@ +Process 7 failed to free memory +Total Processes created 1, Total allocated memory 5, Total Processes +terminated 0, Total freed memory 0, Final memory available 5, Final +smallest and largest fragmented memory sizes 5 and 5, total failed requests:1, number of memory chunks: 1 diff --git a/Assignment6/out/test5.out b/Assignment6/out/test5.out new file mode 100644 index 0000000..75693fd --- /dev/null +++ b/Assignment6/out/test5.out @@ -0,0 +1,5 @@ +Process 3 failed to allocate 5 memory +Process 3 failed to free memory +Total Processes created 2, Total allocated memory 10, Total Processes +terminated 0, Total freed memory 0, Final memory available 0, Final +smallest and largest fragmented memory sizes 0 and 0, total failed requests:2, number of memory chunks: 0 diff --git a/Assignment6/out/test6.out b/Assignment6/out/test6.out new file mode 100644 index 0000000..3490788 --- /dev/null +++ b/Assignment6/out/test6.out @@ -0,0 +1,3 @@ +Total Processes created 3, Total allocated memory 13, Total Processes +terminated 2, Total freed memory 10, Final memory available 7, Final +smallest and largest fragmented memory sizes 7 and 7, total failed requests:0, number of memory chunks: 1 diff --git a/Assignment6/out/test7-a.out b/Assignment6/out/test7-a.out new file mode 100644 index 0000000..dda6f52 --- /dev/null +++ b/Assignment6/out/test7-a.out @@ -0,0 +1,3 @@ +Total Processes created 5, Total allocated memory 5, Total Processes +terminated 2, Total freed memory 2, Final memory available 2, Final +smallest and largest fragmented memory sizes 1 and 1, total failed requests:0, number of memory chunks: 2 diff --git a/Assignment6/out/test7-b.out b/Assignment6/out/test7-b.out new file mode 100644 index 0000000..2cf3468 --- /dev/null +++ b/Assignment6/out/test7-b.out @@ -0,0 +1,3 @@ +Total Processes created 5, Total allocated memory 5, Total Processes +terminated 2, Total freed memory 2, Final memory available 2, Final +smallest and largest fragmented memory sizes 2 and 2, total failed requests:0, number of memory chunks: 1 diff --git a/Assignment6/out/test7-c.out b/Assignment6/out/test7-c.out new file mode 100644 index 0000000..dda6f52 --- /dev/null +++ b/Assignment6/out/test7-c.out @@ -0,0 +1,3 @@ +Total Processes created 5, Total allocated memory 5, Total Processes +terminated 2, Total freed memory 2, Final memory available 2, Final +smallest and largest fragmented memory sizes 1 and 1, total failed requests:0, number of memory chunks: 2 diff --git a/Assignment6/out/test8-a.out b/Assignment6/out/test8-a.out new file mode 100644 index 0000000..2cf3468 --- /dev/null +++ b/Assignment6/out/test8-a.out @@ -0,0 +1,3 @@ +Total Processes created 5, Total allocated memory 5, Total Processes +terminated 2, Total freed memory 2, Final memory available 2, Final +smallest and largest fragmented memory sizes 2 and 2, total failed requests:0, number of memory chunks: 1 diff --git a/Assignment6/out/test8-b.out b/Assignment6/out/test8-b.out new file mode 100644 index 0000000..2cf3468 --- /dev/null +++ b/Assignment6/out/test8-b.out @@ -0,0 +1,3 @@ +Total Processes created 5, Total allocated memory 5, Total Processes +terminated 2, Total freed memory 2, Final memory available 2, Final +smallest and largest fragmented memory sizes 2 and 2, total failed requests:0, number of memory chunks: 1 diff --git a/Assignment6/out/test8-c.out b/Assignment6/out/test8-c.out new file mode 100644 index 0000000..dda6f52 --- /dev/null +++ b/Assignment6/out/test8-c.out @@ -0,0 +1,3 @@ +Total Processes created 5, Total allocated memory 5, Total Processes +terminated 2, Total freed memory 2, Final memory available 2, Final +smallest and largest fragmented memory sizes 1 and 1, total failed requests:0, number of memory chunks: 2