wisemonkeys logo
FeedNotificationProfileManage Forms
FeedNotificationSearchSign in
wisemonkeys logo

Blogs

Different memory allocation strategies

profile
Srushti Chauhan
Jul 27, 2024
2 Likes
0 Discussions
606 Reads

Introduction

In operating systems, memory allocation refers to the process of assigning memory to different processes or programs running on a computer system. Memory allocation is a crucial function in operating systems, managing how memory resources are distributed among various processes. Different strategies have been developed to optimize memory usage and ensure system efficiency. Here are some common memory allocation strategies:

1. Contiguous Memory Allocation

  • Definition: This strategy allocates a single contiguous block of memory to each process.

Contiguous memory allocation is a technique where the operating system allocates a contiguous block of memory to a process. This memory is allocated in a single, continuous chunk, making it easy for the operating system to manage and for the process to access the memory. Contiguous memory allocation is suitable for systems with limited memory sizes and where fast access to memory is important.

Contiguous memory allocation can be done in two ways:-

  • Fixed Partitioning − In fixed partitioning, the memory is divided into fixed-size partitions, and each partition is assigned to a process. This technique is easy to implement but can result in wasted memory if a process does not fit perfectly into a partition.

  • Dynamic Partitioning − In dynamic partitioning, the memory is divided into variablesize partitions, and each partition is assigned to a process. This technique is more efficient as it allows the allocation of only the required memory to the process, but it requires more overhead to keep track of the available memory.

    Advantages of Contiguous Memory Allocation

    • Simplicity − Contiguous memory allocation is a relatively simple and straightforward technique for memory management. It requires less overhead and is easy to implement.

    • Efficiency − Contiguous memory allocation is an efficient technique for memory management. Once a process is allocated contiguous memory, it can access the entire memory block without any interruption.

  • Low fragmentation − Since the memory is allocated in contiguous blocks, there is a lower risk of memory fragmentation. This can result in better memory utilization, as there is less memory wastage.

Disadvantages of Contiguous Memory Allocation

  • Limited flexibility − Contiguous memory allocation is not very flexible as it requires memory to be allocated in a contiguous block. This can limit the amount of memory that can be allocated to a process.

  • Memory wastage − If a process requires a memory size that is smaller than the contiguous block allocated to it, there may be unused memory, resulting in memory wastage.

  • Difficulty in managing larger memory sizes − As the size of memory increases, managing contiguous memory allocation becomes more difficult. This is because finding a contiguous block of memory that is large enough to allocate to a process becomes challenging.

  • External Fragmentation − Over time, external fragmentation may occur as a result of memory allocation and deallocation, which may result in non − contiguous blocks of free memory scattered throughout the system.

2.Non-contiguous Memory Allocation

Non-contiguous memory allocation, on the other hand, is a technique where the operating system allocates memory to a process in non-contiguous blocks. The blocks of memory allocated to the process need not be contiguous, and the operating system keeps track of the various blocks allocated to the process. Non-contiguous memory allocation is suitable for larger memory sizes and where efficient use of memory is important.

Non-Contiguous memory allocation can be done in two ways:-

 1) Paging

  • Definition: Memory is divided into fixed-size blocks called pages, and physical memory is divided into page frames of the same size.
  • How it Works: A process’s memory is divided into pages that can be mapped to any page frame in physical memory. This approach helps avoid external fragmentation and simplifies memory management.

In paging, the memory is divided into fixed-size pages, and each page is assigned to a process. This technique is more efficient as it allows the allocation of only the required memory to the process.

  • Advantages:
    • Eliminates external fragmentation.
    • Simplifies allocation and deallocation.
  • Disadvantages:
    • Can cause internal fragmentation if a process doesn’t use the entire page.

   2)Segmentation

  • Definition: Memory is divided into segments based on the logical organization of the program (e.g., code, data, stack).
  • How it Works: Each segment is of variable length and is managed independently. Segments are referenced by segment number and offset.

In segmentation, the memory is divided into variable-sized segments, and each segment is assigned to a process. This technique is more flexible than paging but requires more overhead to keep track of the allocated segments.

  • Advantages:
    • Supports the logical division of a program.
    • Segments can grow or shrink independently.
  • Disadvantages:
    • Can lead to external fragmentation.
    • Managing variable-sized segments can be complex.

4. Virtual Memory

  • Definition: Provides an abstraction of memory that gives each process the illusion of having a large, contiguous block of memory, even though physical memory may be fragmented.
  • How it Works: Virtual memory systems use paging or segmentation to map virtual addresses to physical addresses. This allows processes to use more memory than physically available by swapping pages in and out of disk storage.
  • Advantages:
    • Supports multitasking by allowing multiple processes to run concurrently.
    • Provides the illusion of a large address space.
  • Disadvantages:
    • Can incur performance overhead due to paging and swapping.
    • Requires efficient management of page tables and disk space.

5. Buddy System

  • Definition: Memory is allocated in blocks that are powers of two, and the system maintains a list of free blocks of each size.
  • How it Works: When a process requests memory, the system finds a suitable block, which may involve splitting larger blocks. If memory is freed, the system attempts to merge adjacent free blocks into larger blocks.
  • Advantages:
    • Reduces fragmentation compared to fixed partitioning.
    • Relatively simple to implement.
  • Disadvantages:
    • Can still suffer from internal fragmentation.
    • May require additional bookkeeping.

6. Slab Allocation

  • Definition: Memory is divided into slabs, where each slab contains objects of a specific size.
  • How it Works: Objects of the same size are allocated from the same slab. This is often used in kernel memory management.
  • Advantages:
    • Reduces fragmentation for objects of fixed size.
    • Efficient for managing small, frequent allocations.
  • Disadvantages:
    • May be less efficient for objects of varying sizes.

7. Allocation with Garbage Collection

  • Definition: This strategy is often used in languages with automatic memory management. The system automatically reclaims memory that is no longer in use.
  • How it Works: Memory is allocated for objects as needed, and a garbage collector periodically scans for and frees unused objects.
  • Advantages:
    • Reduces the programmer’s burden of manual memory management.
    • Can help avoid memory leaks.
  • Disadvantages:
    • Garbage collection can introduce performance overhead.
    • The timing of garbage collection can be unpredictable.

Each strategy has its strengths and trade-offs, and the choice of strategy often depends on the specific requirements and constraints of the system being designed.


Comments ()


Sign in

Read Next

Electronic Evidence in Cyber Forensics

Blog banner

SMARTSHEET MANAGEMENT SOFTWARE

Blog banner

Electronic data interchange

Blog banner

Apache Spark :- Powerful Data Processing Tool

Blog banner

Mutual exclusion

Blog banner

Little Habits, Big Impact: Daily Preschool Routines That Shape the Future

Blog banner

Zero-Day Attack

Blog banner

10 Interesting facts you should know!!!

Blog banner

ADD A SPICE TO YOUR LIFE.

Blog banner

What is thread and alse multithreading

Blog banner

Embracing the power of Modern Machine UNIX

Blog banner

Some facts about Technology

Blog banner

Smartsheet

Blog banner

Reconnaissance

Blog banner

Virtual Memory

Blog banner

What makes Nugget RC Racing Florida’s Most Exciting Racing Events?

Blog banner

Top Career Paths After a B.Com Degree in Mumbai: What’s Next for You?

Blog banner

Layers Of Blockchain

Blog banner

Understanding Input Based Keylogger Activation Systems: Risks and Mitigation

Blog banner

Simple AI Symptom Diagnosis Using LISP – Rule-Based Expert System

Blog banner

How to write a cover letter

Blog banner

Culture Of Ladakh

Blog banner

Deadlock and Starvation in an Operating System

Blog banner

Importance of Website

Blog banner

Navigating the Digital Battlefield: Security Breaches and Effective Countermeasures

Blog banner

Modern operating system

Blog banner

5 Common Faults In Construction Tenders

Blog banner

operating system

Blog banner

The Memory Hierarchy

Blog banner

Who decides your overthinking, anyway?

Blog banner

Multicore and multithreading 171

Blog banner

An Approach To Spyware Detection And Removal

Blog banner

What is semaphore in operating system?

Blog banner

Google classroom

Blog banner

Blockchain Transactions

Blog banner

Famous Indian dishes that where misunderstood to be Indian

Blog banner

Blockchain uses and use cases

Blog banner

MODERN OPERATING SYSTEM

Blog banner

Predictive Analysis - Ek Overview

Blog banner

Explain the concept of ( MIS) Management information systems

Blog banner

undefined

Blog banner

What are Tenders its various types

Blog banner