Memory allocation Flashcards
(9 cards)
What Is Memory Allocation?
Memory allocation is how the operating system gives parts of memory (RAM) to processes so they can run programs.
It decides:
Where a program goes in memory
How much memory it gets
How to manage that memory while the program runs
Two Types of Memory Allocation
Static Allocation:
Memory is assigned at compile time.
Once set, it doesn’t change.
Example: global variables, fixed arrays
Dynamic Allocation:
Memory is assigned at runtime, as needed.
Can grow or shrink using functions like malloc() or free() in C.
Used for structures like linked lists, trees, etc
Problem with Variable Size Allocation
Obvious approach, allocate just memory requested
* Placing things in memory (or on disk, etc.) with such
approach rapidly becomes big problem…
* If we free a large area of memory, disk, …– Tend to place something smaller in space, leaving a gap,
which prevents us from then storing something larger which leads to fragmentation
Fragmentation
Can become severe problem– Sum of un-allocated space can be large– Requires complex de-fragmentation
* Shuffling storage contents– Must be invisible to running processes
Making best use of
Variable Size Regions
Dynamic storage allocation schemes…
– First fit and Next fit
* Always allocate first region of sufficient size found
– Best fit
* Always allocate smallest memory hole of sufficient size
– Worst fit
* Always allocate largest memory hole (of sufficient size)
* Aims to increase chance of later allocation
Variable vs. Fixed Sized Schemes
Variable/ Dynamic allocation schemes:
Allocate requested amount of memory– External fragmentation
* Space left outside/ between allocated memory
Fixed size schemes: Always allocate memory in fixed-sized blocks– Internal fragmentation
* Processes typically get more memory than requested,
rounded up to n * block size, which generally remains unused
Fragmentation Issues
Internal Fragmentation: Wasted space inside an allocated block.
External Fragmentation: Wasted space between allocated blocks.
Buddy Allocation Scheme
Idea is that a memory area can be split in two–Two buddies
- Likewise, two buddies can be combined– Reforming original pair into larger block
- Balances speed and memory use
Slab Allocation
Used in kernels.
Preallocates commonly used memory blocks.
Fast and efficient for objects like process control blocks.