From 7bb3bfd39bf916718208e372196176aa4b63c544 Mon Sep 17 00:00:00 2001 From: Brandon Rodriguez <brodriguez8774@gmail.com> Date: Fri, 23 Apr 2021 18:19:43 -0400 Subject: [PATCH] Minor logic and memory management corrections --- .gitignore | 1 + documents/references.md | 3 +++ part_1/image.cu | 39 +++++++++++++++++++++++++++++++-------- part_1/image.h | 7 ++++++- part_1/logging.cu | 2 +- part_1/main.cu | 13 +++++++++---- part_1/makefile | 5 +++-- part_1/utility.h | 2 +- 8 files changed, 55 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index 0ff488a..b945a25 100644 --- a/.gitignore +++ b/.gitignore @@ -45,4 +45,5 @@ vscode/ # Project-specific ignores go below here. ## input/ +input_backup/ output/ diff --git a/documents/references.md b/documents/references.md index dd34e5e..47ce71c 100644 --- a/documents/references.md +++ b/documents/references.md @@ -47,6 +47,9 @@ Various references used in project. * <https://stackoverflow.com/a/59553786> * <https://stackoverflow.com/a/5420568> +#### Memory Management +* <https://www.geeksforgeeks.org/delete-in-c/> + ## CUDA References diff --git a/part_1/image.cu b/part_1/image.cu index 06952d2..ee9c2b1 100644 --- a/part_1/image.cu +++ b/part_1/image.cu @@ -79,6 +79,9 @@ void Image::import_image_file() { logger.debug("Image::import_image_file():"); logger.debug(""); + logger.info("Attempting to import image data..."); + logger.info("Data from: \"" + input_path + "\""); + // Open input file. std::ifstream input_file; input_file.open(input_path, std::ios::binary | std::ios::in); @@ -90,9 +93,13 @@ void Image::import_image_file() { // File opened. Grab data. std::string header; input_file >> header; - if (strcmp(header.c_str(), "P6") != 0) { - throw("Can't read input file"); - } + // if (strcmp(header.c_str(), "P6") != 0) { + // // throw("Can't read input file"); + // logger.error("Wrong file type, oops: "); + // logger.error(header); + // logger.error(input_path); + // logger.error(""); + // } // Save image values to class. input_file >> width >> height >> bit_depth; @@ -144,6 +151,7 @@ Image::Image() { } } + /** * Constructor that takes input path to image file. * Output path is determined based on parsing input path. @@ -153,7 +161,9 @@ Image::Image(std::string user_path) { logger.debug(" user_path: " + user_path); logger.debug(""); - // Re-validate path for saving to class.. + logger.info("Constructing image class."); + + // Re-validate path for saving to class. path_validator_struct* return_struct = validate_path(user_path); int path_type = return_struct->file_type; if (return_struct->err_code) { @@ -166,9 +176,22 @@ Image::Image(std::string user_path) { calculate_paths(user_path); import_image_file(); } else { - logger.error("Provided path is not to image file. Class initialization failed."); + logger.error("Provided path is not an image file. Class initialization failed."); return; } + + logger.info("Image class created."); +} + + +/** + * Deconstructor. + */ +Image::~Image() { + logger.debug("Deconstructing image class"); + + // Deallocate memory objects. + delete[] pixel_arr; } //endregion Constructors. @@ -186,9 +209,9 @@ void Image::display_properties() { logger.info(""); logger.info("input file path: " + input_path); logger.info("output file path: " + output_path); - logger.info("width: " + width); - logger.info("height: " + height); - logger.info("bit depth: " + bit_depth); + logger.info("width: " + std::to_string(width)); + logger.info("height: " + std::to_string(height)); + logger.info("bit depth: " + std::to_string(bit_depth)); logger.info(""); } diff --git a/part_1/image.h b/part_1/image.h index 4d9eb46..65b5ba1 100644 --- a/part_1/image.h +++ b/part_1/image.h @@ -4,9 +4,9 @@ // System Import Headers. +#include <cctype> #include <cstdio> #include <cstdlib> -#include <cctype> #include <filesystem> #include <fstream> #include <iostream> @@ -86,6 +86,11 @@ class Image { */ Image(std::string user_path); + /** + * Deconstructor. + */ + ~Image(); + //endregion Constructors. diff --git a/part_1/logging.cu b/part_1/logging.cu index 5fb3771..e281960 100644 --- a/part_1/logging.cu +++ b/part_1/logging.cu @@ -17,7 +17,7 @@ */ Logging::Logging() { std::filesystem::path cwd = std::filesystem::current_path(); - core_logging_folder = cwd.string() + "/log/"; + core_logging_folder = cwd.string() + "/logs/"; // Check if logging directory exists. struct stat info; diff --git a/part_1/main.cu b/part_1/main.cu index 5710a71..d1094ee 100644 --- a/part_1/main.cu +++ b/part_1/main.cu @@ -4,9 +4,9 @@ // System Import Headers. +#include <cctype> #include <cstdio> #include <cstdlib> -#include <cctype> #include <filesystem> #include <fstream> #include <iostream> @@ -98,6 +98,10 @@ void process_dir(std::string path_str) { logger.debug(" path_str: " + path_str); logger.debug(""); + logger.info(""); + logger.info(""); + logger.info(""); + logger.info(""); logger.info("Handling dir."); // Process all files in directory. @@ -122,9 +126,6 @@ void process_dir(std::string path_str) { // Process file. process_file(file_path_str); } - - // Send individual file path for processing. - process_file(entry.path()); } } @@ -137,6 +138,10 @@ void process_file(std::string path_str) { logger.debug(" path_str: " + path_str); logger.debug(""); + logger.info(""); + logger.info(""); + logger.info(""); + logger.info(""); logger.info("Handling file."); Image image(path_str); diff --git a/part_1/makefile b/part_1/makefile index 7540236..85404c9 100644 --- a/part_1/makefile +++ b/part_1/makefile @@ -31,5 +31,6 @@ run: $(TARGET) # Compile target if dependencies update. Then run. valgrind: $(TARGET) - @rm ./logs/vg/* - valgrind --leak-check=full --suppressions=valgrind_supression.txt --log-file=./logs/vg/vg.%p ./$(TARGET) $(ARGS) +# @rm ./logs/vg/* +# valgrind --leak-check=full --log-file=./logs/vg/vg.%p ./$(TARGET) $(ARGS) + valgrind --leak-check=full ./$(TARGET) $(ARGS) diff --git a/part_1/utility.h b/part_1/utility.h index d20726d..fea1b97 100644 --- a/part_1/utility.h +++ b/part_1/utility.h @@ -4,9 +4,9 @@ // System Import Headers. +#include <cctype> #include <cstdio> #include <cstdlib> -#include <cctype> #include <filesystem> #include <fstream> #include <iostream> -- GitLab