{"id":29267154,"url":"https://github.com/rrsmart8/memory-allocator","last_synced_at":"2025-07-04T17:16:54.491Z","repository":{"id":207854985,"uuid":"719760691","full_name":"rrsmart8/Memory-Allocator","owner":"rrsmart8","description":"Using Data Structures to create  malloc(), calloc(), realloc() functions.","archived":false,"fork":false,"pushed_at":"2025-04-01T20:39:22.000Z","size":13,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-01T21:34:15.756Z","etag":null,"topics":["heap","operating-system","system-calls"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rrsmart8.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-11-16T21:04:25.000Z","updated_at":"2025-04-01T20:39:26.000Z","dependencies_parsed_at":"2023-11-18T02:10:45.571Z","dependency_job_id":"19740d37-8a19-4f74-97b0-0c15c9270668","html_url":"https://github.com/rrsmart8/Memory-Allocator","commit_stats":null,"previous_names":["rrsmart8/memory-allocator"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rrsmart8/Memory-Allocator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rrsmart8%2FMemory-Allocator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rrsmart8%2FMemory-Allocator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rrsmart8%2FMemory-Allocator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rrsmart8%2FMemory-Allocator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rrsmart8","download_url":"https://codeload.github.com/rrsmart8/Memory-Allocator/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rrsmart8%2FMemory-Allocator/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263586054,"owners_count":23484498,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["heap","operating-system","system-calls"],"created_at":"2025-07-04T17:16:53.748Z","updated_at":"2025-07-04T17:16:54.479Z","avatar_url":"https://github.com/rrsmart8.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Memory Allocator\n\nA simple yet powerful dynamic memory management system that mimics the behavior of `malloc`, `free`, `calloc`, and `realloc`, tailored for both **small** and **large** memory allocations.\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"./memory_block.png\" alt=\"Memory Allocator Diagram\" width=\"600\"/\u003e\n\u003c/p\u003e\n\n\n---\n\n##  Features\n\n- Custom `malloc`, `free`, `calloc`, `realloc` functions using data structures\n-  Memory coalescing to reduce fragmentation\n-  Block splitting for efficient space use\n- Separate strategies for small \u0026 large allocations\n\n---\n\n## Usage\n\nInclude the header and link the implementation file:\n\n```c\n#include \"osmem.h\"\n```\n\nThen use the custom allocation functions just like standard ones:\n\n```c\nvoid *ptr = os_malloc(64);\nos_free(ptr);\n```\n\n---\n\n## Functions\n\n### `void *os_malloc(size_t size)`\n\u003e Allocates a block of memory of the specified size.  \nUses internal data structures to track and deliver usable payloads.\n\n---\n\n### `void os_free(void *ptr)`\n\u003e Frees the memory block pointed to by `ptr`.  \nHandles both `sbrk`-based and `mmap`-based memory allocations.\n\n---\n\n### `void *os_calloc(size_t nmemb, size_t size)`\n\u003e Allocates memory for an array and **initializes it to zero**.  \nPerfect for ensuring clean, zeroed memory.\n\n---\n\n### `void *os_realloc(void *ptr, size_t size)`\n\u003e Resizes a previously allocated block.  \nHandles all edge cases like expansion, shrinking, or creating new blocks.\n\n---\n\n## Memory Allocation Strategies\n\n### Small Allocations (`\u003c CHUNK size`)\n- Uses `sbrk` syscall for linear heap expansion.\n- Preallocates a chunk on first use.\n- Finds suitable free blocks or expands the heap.\n\n### Large Allocations (`\u003e= CHUNK size`)\n- Uses `mmap` syscall for direct mapping of large memory blocks.\n\n---\n\n## Optimizations\n\n### Memory Coalescing\n\u003e Adjacent free blocks are **merged** to prevent fragmentation.\n\n###  Block Splitting\n\u003e Large blocks are **split** into smaller parts when possible.\n\n---\n\n## 📁 File Structure\n\n```\n├── osmem.h         # Header file with function declarations\n├── osmem.c         # Implementation of the memory allocator\n└── README.md       # You are here!\n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frrsmart8%2Fmemory-allocator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frrsmart8%2Fmemory-allocator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frrsmart8%2Fmemory-allocator/lists"}