Skip to content

supunrandika98/Buddy_System_Memory_Allocator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simply the Buddy System is a memory management technique designed to allocate and deallocate memory in a way that manage memory efficiently. It works by dividing memory into blocks of sizes that are powers of two fixed-size blocks, and whenever a process requests memory, the system finds the smallest available block that can accommodate the requested memory size.

Functionality and Features of the Buddy System Memory Management System

  1. Memory Initialization: The system starts with an initial block of memory (e.g., 1024 KB) marked as free. This memory block is used to allocate and deallocate memory dynamically as per the user's requests. The system ensures that memory starts with a predefined large block that can be divided into smaller blocks for allocation.

  2. Memory Allocation: Description: Users can request memory allocation by specifying the size of the block they wish to allocate. The system will find the smallest available block that is large enough and split it if necessary to meet the requested size. The system can handle dynamic allocation requests and track allocated memory.

  3. Memory Deallocation: Users can request memory deallocation by specifying the block size to free up. The system will find the allocated block of the requested size, mark it as free, and clear the associated data. Deallocation allows previously allocated memory to be reclaimed. After deallocation, the system will try to merge adjacent free blocks to reduce fragmentation and efficiently manage available memory.

  4. Block Splitting (Buddy System): When a memory block is allocated, it is recursively split into two smaller blocks of equal size until the block size matches the requested size. The system ensures that memory is allocated in powers of 2 by recursively splitting larger blocks. Each split creates two "buddy" blocks, ensuring that the remaining memory is still managed efficiently.

  5. Block Merging: After memory is deallocated, adjacent free blocks of the same size are merged back together to form a larger block, reducing fragmentation. Merging blocks ensures that the system does not run into memory fragmentation, where small free blocks are scattered across the system. This process is repeated as long as possible to maximize memory utilization.

  6. Memory Status Display: The system displays the current memory status after each allocation or deallocation. It shows the size of each block and whether it is free or allocated. For allocated blocks, the associated allocation data (e.g., process ID) is displayed. Real-time memory status updates allow users to monitor how memory is being allocated, deallocated, and merged. This feature helps visualize the state of memory, providing users with insights into memory usage and fragmentation.

  7. Allocation Data: When a block is allocated, the system stores data (e.g., process ID) in the allocated block to keep track of what the memory is being used for. This feature makes the system suitable for real-world applications where memory needs to be associated with specific tasks or processes. Allows easy identification of which process is using a specific memory block.

  8. User Interaction through Console: The system interacts with the user through a simple console interface. The user can input their choices and request memory allocation or deallocation. Supports continuous operation, allowing users to perform multiple operations (allocation, deallocation, display status) in sequence without restarting the system. The system prompts for user input and displays results, making it intuitive for users to manage memory.

  9. Dynamic Allocation Size: The system automatically adjusts the allocated memory size based on the next available power of 2. It ensures that even if the user requests an odd-sized block (e.g., 100 KB), the system will allocate the smallest power of 2 that is greater than or equal to the requested size (e.g., 128 KB). It ensures memory is allocated efficiently by always using powers of 2, which fits the Buddy System algorithm's design. Eliminates the need for users to worry about memory size optimization, as the system takes care of it automatically.

  10. Handling Insufficient Memory: If a memory allocation request cannot be satisfied due to insufficient memory, the system will notify the user. Provides feedback to the user when the requested memory cannot be allocated, preventing confusion and helping users make informed decisions. Offers error handling when deallocating memory (e.g., if the block cannot be found).

  11. Continuous Memory Management: The system continues to function until the user decides to exit. It allows users to allocate or deallocate memory in any order, ensuring continuous memory management during operation. No need to restart the system to perform different operations. Flexible memory management that can handle dynamic memory allocation and deallocation requests.

  12. Exit Option: Users can choose to exit the program when they are done managing memory.

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages