🚀 Building my own memory allocator in C Today I implemented a basic version of malloc from scratch. Instead of relying on the system allocator, I manually managed memory by: -->Creating a memory pool -->Storing metadata for each block (size, status, next pointer) -->Returning usable memory using pointer arithmetic One concept that really clicked for me: 👉 The pointer returned to the user does NOT point to the start of the block Internally, memory looks like: [ metadata ][ usable memory ] And we return: (curr + 1) This helped me better understand how memory is actually structured and managed at a low level. Next step: handling multiple blocks and improving allocation logic. #EmbeddedSystems #SystemsProgramming #CProgramming #MemoryManagement
Building Custom Memory Allocator in C from Scratch
More Relevant Posts
-
💻 Understanding Memory Allocation in C Today, I explored a fundamental concept in C_programming Memory Allocation and how it directly impacts performance and efficiency. # What is Memory Allocation? Memory allocation refers to the process of reserving space in RAM for storing data during program execution. ## In C, there are two primary types: 1. Static Memory Allocation Allocated at compile time. The size is fixed and cannot be changed later. Example: int a = 10; 2. Dynamic Memory Allocation Allocated at runtime, allowing flexible memory usage based on program needs. To use dynamic allocation, we include: #include <stdlib.h> * Key Functions: • malloc() – Allocates a single block of memory int *ptr = (int*) malloc(5 * sizeof(int)); • calloc() – Allocates multiple blocks and initializes them to zero int *ptr = (int*) calloc(5, sizeof(int)); • realloc() – Resizes previously allocated memory ptr = (int*) realloc(ptr, 10 * sizeof(int)); • free() – Releases allocated memory back to the system free(ptr); Best Practices: ✔ Always free dynamically allocated memory to avoid memory leaks ✔ Use pointers carefully when working with dynamic memory ✔ Choose dynamic allocation when flexibility is required Static allocation is simple but limited, while dynamic allocation offers flexibility and efficient memory usage when handled correctly. #Programming #CProgramming #MemoryManagement #LearningJourney
To view or add a comment, sign in
-
🚀 Just published my Unified Memory Debugger – a production‑inspired C++ memory debugging suite. It combines three integrated components: (i) Raw allocator tracker (global new/delete override) (ii) Logical dataset tracker (named objects + age) (iii) Smart pointer connection pool (RAII) 🎯 The goal: Provide a plug‑and‑play memory debugging tool for large‑scale scientific software like GROMACS, which has known memory leak and excessive consumption issues. 📂 Project is still in progress – but the current code is ready to test. 🔗 GitHub: https://lnkd.in/dTt4tiYA Feedback, issues, and contributions welcome! 🙏 #Cpp #MemoryManagement #Debugging #HighPerformanceComputing #GROMACS #OpenSource
To view or add a comment, sign in
-
Ever needed to check what's coming next in a buffer without consuming it? 🤔 Before Go 1.26, you had to read data into a temporary slice or maintain complex cursor logic. Go 1.26 introduces Buffer.Peek(n) → returns next n bytes without advancing buffer position → perfect for protocols, parsers, and stream processing → eliminates unnecessary allocations. Traditional approach required copying or manual tracking: → Read bytes, store cursor, seek back if not needed → Creates temporary slices and extra memory overhead → Adds complexity to parsing logic With Peek(), you get clean, efficient inspection: → Peek at upcoming bytes, decide what to do next → If you need them, call Read; if not, just continue → Zero allocation for the peek operation itself Which parsing scenarios would benefit most from Buffer.Peek()? #GoLang #Go126 #ProgrammingTips #DeveloperTools #StreamProcessing
To view or add a comment, sign in
-
-
🚀 Project Showcase: Virtual Memory Optimization System Excited to share my latest project where I worked on designing and implementing a Virtual Memory Optimization System 💻 🔍 This project focuses on improving system performance by efficiently managing memory usage and reducing page faults using optimized page replacement strategies. 📌 Key Highlights: • Implemented smart memory allocation techniques • Optimized page replacement algorithms (like FIFO, LRU, etc.) • Reduced system overhead and improved performance • Simulated real-world memory management scenarios 📌Team Members: 1. Kittu 2. Annesha Naha 3. Snehil Raj 🎯 Outcome: Achieved better memory utilization and faster execution by minimizing unnecessary memory swaps. Thanks for my teacher Mr.Sachin Kumar Chawla and Mr. Pushpendra Kumar Pateriya ✴️ 🔗 LinkedIn Link:https://lnkd.in/gUbD5bdJ GitHub Repository: https://lnkd.in/gt8j_zsz 📽️ Watch the full demo video below to see how the system works in action! 💬 I’d love to hear your feedback and suggestions. #OperatingSystem #VirtualMemory #SystemDesign #TechProject #ComputerScience #Coding #StudentDeveloper #Innovation
To view or add a comment, sign in
-
Day 19 / 90 — Software Engineering Challenge Today was focused on revising important problem-solving patterns and strengthening understanding. DSA Practice Revisited: • Largest Subarray with Sum 0 • Count Subarrays with XOR = K • Merge Overlapping Intervals • Merge Two Sorted Arrays (without extra space) Key learnings: • Prefix sum + hashmap is powerful for subarray problems • XOR helps solve problems efficiently with unique properties • Interval problems require sorting + careful merging logic • In-place operations help optimize space complexity Focusing more on understanding patterns deeply rather than just solving new problems. #90DaysOfCode #DSA #ProblemSolving #SoftwareEngineering #LearningInPublic
To view or add a comment, sign in
-
Day22 of 100 Days competitive Programming solving:- problem statement:- Problem: Longest Subarray with Sum Less Than K Given an array of non-negative integers arr[] and an integer k, find the length of the longest contiguous subarray such that the sum of its elements is strictly less than k. A subarray is a contiguous part of the array. input 2,5,1,7,10 k=14 Output 3
To view or add a comment, sign in
-
-
The thing that I learned while building my custom memory allocator is that memory doesn’t work the way I thought it did. I used to think when we call malloc(20), the OS gives exactly 20 bytes. That’s not true. The OS actually allocates memory in fixed-size chunks called pages (typically 4KB). Your program just uses a small part of it. So what happens to the rest? That’s where a memory allocator comes in. It takes these large pages from the OS and breaks them into smaller blocks to efficiently serve multiple allocation requests. 𝐊𝐞𝐲 𝐢𝐝𝐞𝐚: OS manages pages → Allocator manages blocks inside those pages Understanding this completely changed how I look at memory. #SystemsProgramming #MemoryManagement #OperatingSystems #CProgramming
To view or add a comment, sign in
-
-
For those who use local LLMs. From yesterday you can test TurboQuant in vLLM in nighly version. It's not official release, so some stuff still may not work. We also got new Qwen. Probably, it's time to start diving into local coding and maybe try to do some finetuning and see how far we can push small models to write production ready code. https://lnkd.in/dUPrgMHi
To view or add a comment, sign in
-
The most critical behaviors in real-time systems – scheduling, timing, concurrency – are largely invisible at runtime. That's one of the core challenges in teaching this subject, and it's what motivated this guest post. Florent Goutailler, Associate Professor at Télécom Saint-Etienne, shares how he integrated runtime visualization into his real-time embedded systems course – and what changed when students could actually see their system's behavior unfold over time. Instead of debugging with printf statements or breakpoints, students follow execution as it happens: observing when tasks run or block, how priorities interact, and whether timing requirements are actually met. The result is a shift from assumption to direct observation – and from theory to the habits of practicing engineers. Read the full guest post to see how visualization is bridging the gap between classroom concepts and real-world embedded systems practice. Link in the comments 🔗
To view or add a comment, sign in
-
-
👉 Question-60 A strong understanding of dynamic memory, double pointers, and hidden leaks is essential in embedded systems. 👉 What will be the output of the following code❓ #include <stdio.h> #include <stdlib.h> void fun(int **p) { *p = (int *)malloc(sizeof(int)); **p = 100; } int main() { int *ptr = (int *)malloc(sizeof(int)); *ptr = 50; fun(&ptr); printf("%d\n", *ptr); return 0; } Options: A) 50 B) 100 C) Garbage value D) Runtime error 💬 Kindly drop your answer in the comments along with your reasoning. ⚠️ Small hint: --> Old memory lost (memory leak) --> Pointer overwritten #embeddedsystems #doublepointers #firmwaredevelopment #memory
To view or add a comment, sign in
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development