Compare commits
3 Commits
2d2aaa903b
...
425d419fd3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
425d419fd3 | ||
|
|
3d3e168e38 | ||
|
|
f0e546a969 |
@@ -1,4 +1,4 @@
|
|||||||
# Lab 4 — Memory Diagrams and Memory Debugging
|
# Memory Diagrams and Memory Debugging
|
||||||
|
|
||||||
## Checkpoint 1
|
## Checkpoint 1
|
||||||
*estimate: 30-45 minutes*
|
*estimate: 30-45 minutes*
|
||||||
@@ -31,7 +31,7 @@ Read lecture notes [6.7](../../lectures/06_memory#67-memory-debugging), [6.8](..
|
|||||||
|
|
||||||
Please download the following 4 files needed for this lab:
|
Please download the following 4 files needed for this lab:
|
||||||
|
|
||||||
[buggy_lab4.cpp](./buggy_lab4.cpp)
|
[buggy_lab.cpp](./buggy_lab.cpp)
|
||||||
[first.txt](./first.txt)
|
[first.txt](./first.txt)
|
||||||
[middle.txt](./middle.txt)
|
[middle.txt](./middle.txt)
|
||||||
[last.txt](./last.txt)
|
[last.txt](./last.txt)
|
||||||
@@ -39,7 +39,7 @@ Please download the following 4 files needed for this lab:
|
|||||||
## Checkpoint 2
|
## Checkpoint 2
|
||||||
*estimate: 20-40 minutes*
|
*estimate: 20-40 minutes*
|
||||||
|
|
||||||
For Checkpoint 2 of this lab, we will heavily rely on dynamic memory to find the average and smallest number for a set of data from an input file. You will use a memory debugging tool such as DrMemory or Valgrind to fix memory errors and leaks in buggy_lab4.cpp. Make sure to download the provided .txt files as well.
|
For Checkpoint 2 of this lab, we will heavily rely on dynamic memory to find the average and smallest number for a set of data from an input file. You will use a memory debugging tool such as DrMemory or Valgrind to fix memory errors and leaks in buggy_lab.cpp. Make sure to download the provided .txt files as well.
|
||||||
First take a look at the code inside the identifyMeanAndMin() function. You will notice that the syntax used
|
First take a look at the code inside the identifyMeanAndMin() function. You will notice that the syntax used
|
||||||
throughout the program may be a little different than what you are used to. Try and familiarize yourself with
|
throughout the program may be a little different than what you are used to. Try and familiarize yourself with
|
||||||
this syntax before you start working on the assignment. What does this line of code do?
|
this syntax before you start working on the assignment. What does this line of code do?
|
||||||
@@ -52,13 +52,13 @@ Whats going on inside the *for* loop? If you are stuck on this, ask a mentor or
|
|||||||
soon as possible and refer back to your lecture notes on pointers and arrays.
|
soon as possible and refer back to your lecture notes on pointers and arrays.
|
||||||
Once you have done this, compile the program using:
|
Once you have done this, compile the program using:
|
||||||
```console
|
```console
|
||||||
g++ buggy_lab4.cpp -o buggy_lab4.out -g -Wall
|
g++ buggy_lab.cpp -o buggy_lab.out -g -Wall
|
||||||
```
|
```
|
||||||
|
|
||||||
Try running the program normally using:
|
Try running the program normally using:
|
||||||
|
|
||||||
```console
|
```console
|
||||||
./buggy_lab4.out
|
./buggy_lab.out
|
||||||
```
|
```
|
||||||
|
|
||||||
You will notice that a segmentation fault occurs. Now run this program using either Valgrind or DrMemory. If running using Valgrind, remember to use --leak-check=yes or --leak-check=full.
|
You will notice that a segmentation fault occurs. Now run this program using either Valgrind or DrMemory. If running using Valgrind, remember to use --leak-check=yes or --leak-check=full.
|
||||||
@@ -67,11 +67,11 @@ Your memory debugger should give you more context as to why a segmentation fault
|
|||||||
|
|
||||||
It is highly recommended that you tackle one part at a time. For example, after adding a few lines of code to part 1, you will now receive different memory errors when you recompile and run the program using your memory debugger. Similarly, fixing all memory errors in part 2 will generate different memory errors that should be resolved in part 3.
|
It is highly recommended that you tackle one part at a time. For example, after adding a few lines of code to part 1, you will now receive different memory errors when you recompile and run the program using your memory debugger. Similarly, fixing all memory errors in part 2 will generate different memory errors that should be resolved in part 3.
|
||||||
|
|
||||||
In part 2 of buggy_lab4.cpp, the goal is to print out the contents of intArray in reverse order, while also calculating the sum of all elements in the array and keeping track of the smallest number encountered. Solutions that attempt to print the contents of the array in a different manner or end up with the wrong
|
In part 2 of buggy_lab.cpp, the goal is to print out the contents of intArray in reverse order, while also calculating the sum of all elements in the array and keeping track of the smallest number encountered. Solutions that attempt to print the contents of the array in a different manner or end up with the wrong
|
||||||
value for the smallest number found or sum won't be accepted.
|
value for the smallest number found or sum won't be accepted.
|
||||||
Note that:
|
Note that:
|
||||||
- You are only allowed to modify or add code when asked to. This would be between the comments that
|
- You are only allowed to modify or add code when asked to. This would be between the comments that
|
||||||
indicate parts 1, 2, and 3 inside buggy_lab4.cpp. Do not modify other parts of the code or create any
|
indicate parts 1, 2, and 3 inside buggy_lab.cpp. Do not modify other parts of the code or create any
|
||||||
helper functions.
|
helper functions.
|
||||||
- You are not allowed to declare new variables; the ones provided are more than enough. Hint: how do
|
- You are not allowed to declare new variables; the ones provided are more than enough. Hint: how do
|
||||||
we create memory on the heap?
|
we create memory on the heap?
|
||||||
@@ -79,9 +79,9 @@ we create memory on the heap?
|
|||||||
|
|
||||||
**You will receive no credit if you do not follow the above restrictions.**
|
**You will receive no credit if you do not follow the above restrictions.**
|
||||||
|
|
||||||
**To receive credit for this checkpoint**: Fix buggy_lab4.cpp so that it successfully prints out the average
|
**To receive credit for this checkpoint**: Fix buggy_lab.cpp so that it successfully prints out the average
|
||||||
and smallest number for a given set of data and is free of all memory errors and leaks on your local machine.
|
and smallest number for a given set of data and is free of all memory errors and leaks on your local machine.
|
||||||
Submit buggy_lab4.cpp on Submitty and verify that there are no memory errors there as well and show a
|
Submit buggy_lab.cpp on Submitty and verify that there are no memory errors there as well and show a
|
||||||
mentor or TA both results. Also explain to a mentor TA what you added or modified in the program to
|
mentor or TA both results. Also explain to a mentor TA what you added or modified in the program to
|
||||||
resolve all memory errors.
|
resolve all memory errors.
|
||||||
|
|
||||||
@@ -116,7 +116,7 @@ Mismatched free() / delete / delete []
|
|||||||
|
|
||||||
**To receive credit for this checkpoint**, discuss your answers to these questions with a TA or mentor.
|
**To receive credit for this checkpoint**, discuss your answers to these questions with a TA or mentor.
|
||||||
|
|
||||||
## Checkpoint 4
|
<!-- ## Checkpoint 4
|
||||||
*remainder of the lab time*
|
*remainder of the lab time*
|
||||||
|
|
||||||
For this checkpoint, you team up with one or two other students from your lab section. Our TA or mentor will pick one problem from the practice packet for you two (or three) to work together as a group. You should not look at the posted solutions. Work as a group (e.g., pair programming!) to come up with a complete solution to the problem.
|
For this checkpoint, you team up with one or two other students from your lab section. Our TA or mentor will pick one problem from the practice packet for you two (or three) to work together as a group. You should not look at the posted solutions. Work as a group (e.g., pair programming!) to come up with a complete solution to the problem.
|
||||||
@@ -125,4 +125,4 @@ Once you have completed and proofread and triple-checked your answer, launch you
|
|||||||
|
|
||||||
Then, write a simple test case to exercise your solution. Compile and run the code. As time follows, fix bugs in your solution and improve and expand your test cases.
|
Then, write a simple test case to exercise your solution. Compile and run the code. As time follows, fix bugs in your solution and improve and expand your test cases.
|
||||||
|
|
||||||
**To complete this checkpoint**, When about 10 minutes remain in the lab, the TA and mentors will circulate through the room to finalize checkoffs. Show them your initial solution, and explain the typos and errors you found and debugged in working through your computer tested solution. Explain your testing & debugging process.
|
**To complete this checkpoint**, When about 10 minutes remain in the lab, the TA and mentors will circulate through the room to finalize checkoffs. Show them your initial solution, and explain the typos and errors you found and debugged in working through your computer tested solution. Explain your testing & debugging process.-->
|
||||||
|
|||||||
Reference in New Issue
Block a user