The file Memory.cpp in the repository Memory contains many memory resource problems described in the notes.
Compile and run the program on your platform (i.e., your compiler and operating system). You may or may not see a memory-related issue during the build and run.
Go to a system where you can run valgrind. Following the instructions in the Guide: Valgrind, compile and run valgrind on the program.
Fix the memory resource problems in Memory.cpp by:
new and delete operatorsDo this for each section one by one committing each section separately. Get the code to the point where it compiles and runs successfully, and you have a clean Valgrind run. For a commit message, use the verb "Fix" and the error given in the // @error comment.
If you do any of the following, your score will be a 0:
producer() and consumer()producer() or consumer()std::unique_ptrOnce done, tag this in Git as memoryfixed. Make sure to git push before you create the tag.
Note: The function consumer() is not just a function for deleting memory. That is not the entire purpose of consumer(). This is indicated by the:
which is the universal (code example) symbol for "Other processing will occur, but we are ignoring it for now to make a point". Some example of what could occur in producer/consumer, in addition to memory allocation/deallocation:
| Scenario | Producer Action | Consumer Action |
|---|---|---|
| Image Processing | Load an image from disk | Process the image (apply filters, resize, save output) |
| Logging | Create a log entry with explanation, severity, and timestamp | Write the log entry to a file |
| Database Connection | Initialize a database connection | Use the connection to execute a query or transaction |
| Asynchronous Task Processing | Produce work items (e.g., tasks) | Retrieve a task from a shared queue and process |