Skip to content

Conversation

@iledesma08
Copy link
Owner

@iledesma08 iledesma08 commented Mar 27, 2025

Pull Request Summary

Memory Management Project

Overview

This PR includes updates and implementations aimed at improving the custom memory management library. The focus has been on optimizing functionality for malloc, free, calloc, realloc, and memory logging to ensure robust memory operations across various scenarios. The changes include enhanced thread-safety, detailed logging, and efficient memory handling strategies.

Key Features and Changes

  1. Memory Allocation (malloc.c):

    • Refactored the my_malloc function for better thread-safety and clearer allocation logic.
    • Added support for dynamic memory extension via extend_heap.
    • Enhanced alignment handling to ensure compatibility with hardware memory requirements.
  2. Memory Deallocation (free.c):

    • Improved my_free to handle merging of adjacent free blocks via the fusion function.
    • Ensured proper tracking of freed memory and error handling for invalid pointers.
    • Integrated optional unmapping for releasing memory to the system when required.
  3. Zero-Initialized Allocation (calloc.c):

    • Implemented my_calloc, which ensures zero-initialized memory allocation.
    • Addressed edge cases where multiplication of elements and size could cause overflow.
  4. Memory Reallocation (realloc.c):

    • Redesigned my_realloc to allocate new blocks only when necessary and copy data efficiently.
    • Utilized a helper function copy_block for safe data transfer between memory blocks.
    • Improved logging for realloc operations to include both old and new block sizes.
  5. Memory Logging (mem_logging.c):

    • Added detailed logging of allocation and deallocation operations.
    • Implemented mechanisms to track operation IDs and cumulative memory usage.
    • Ensured logs are safely stored and can be cleaned up after operations.
  6. Heap and Metrics Management (memory.c, mem_metrics.c):

    • Provided utilities for checking heap consistency and calculating fragmentation.
    • Integrated tracking for total allocated and freed memory.
    • Added functionality for reporting memory usage in a user-friendly format.

Conclusion

This PR introduces robust memory management capabilities while maintaining clarity and maintainability. While automated testing coverage is moderate, the manual tests provide confidence in the library's reliability and resilience.

Filesearch implementation on shell

See issue #2

Memory usage metrics on monitor

See issue #2

Project Related Questions

See issue #4

Mistery Challenge Solving steps

See issue #5

@iledesma08 iledesma08 added the epic Organize larger projects/tasks label Mar 27, 2025
@iledesma08 iledesma08 self-assigned this Mar 27, 2025
@iledesma08 iledesma08 merged commit 9d8f5e5 into master Mar 27, 2025
1 check failed
@iledesma08 iledesma08 deleted the alpha branch March 27, 2025 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

epic Organize larger projects/tasks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants