Skip to content

This repository contains an implementation of a custom dynamic memory allocator in C, mimicking the behavior of the standard malloc and free functions. The allocator uses a fixed-size memory buffer and a linked list-based approach to manage memory blocks. It supports splitting and merging of memory blocks to optimize memory usage.

Notifications You must be signed in to change notification settings

Keeththi2003/MyMalloc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

2 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ› ๏ธ MyMalloc: Custom Dynamic Memory Allocator in C

Welcome to MyMalloc, a lightweight and efficient memory allocator built from scratch in C! This project replicates the behavior of standard malloc and free functions, using a fixed memory pool and a linked list to manage memory blocks.


๐Ÿš€ Features

  • Dynamic Memory Allocation
    Mimics malloc to allocate memory dynamically.

  • Memory Deallocation
    Implements a custom free function to reclaim memory.

  • Block Splitting and Merging
    Efficiently handles fragmentation by splitting large blocks and coalescing adjacent free blocks.

  • Fixed Memory Pool
    Uses a statically allocated array of 25,000 bytes as the memory pool.


๐Ÿ—๏ธ How It Works

The allocator uses a linked list of memory blocks to manage allocations.
Each block contains:

  • The size of the block.
  • Whether it is free or allocated.
  • A pointer to the next block.

The MyMalloc function searches for a suitable block to fulfill the memory request. If the block is larger than required, it splits the block and reuses the remaining memory. When freeing memory, MyFree merges adjacent free blocks to reduce fragmentation.


๐Ÿ“‚ File Structure

About

This repository contains an implementation of a custom dynamic memory allocator in C, mimicking the behavior of the standard malloc and free functions. The allocator uses a fixed-size memory buffer and a linked list-based approach to manage memory blocks. It supports splitting and merging of memory blocks to optimize memory usage.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages