j-eff-hacker/linked_list_using_C

GitHub: j-eff-hacker/linked_list_using_C

Stars: 0 | Forks: 0

## 🛠️ What I Built (Project Milestones) In this project, I bypassed high-level syntax shortcuts to build a virtual memory controller entirely from scratch using primitive arrays in C. I successfully mapped out and coded three critical systems: 1. **The Virtual RAM Allocation Pool:** I managed data and memory tracking independently by creating two parallel arrays (`data[]` and `pointer[]`). I utilized a global `free_index` tracking variable to manually handle element allocation, entirely removing any dependency on the operating system's `malloc`. 2. **The Logical Map Scanner:** I wrote a custom traversal loop that completely ignores standard physical array ordering ($0, 1, 2\dots$). Instead, the scanner dynamically jumps through elements based on index pointers via `current = pointer[current]`. 3. **Floyd's Cycle Detector:** I implemented an index-based version of the Fast and Slow pointer rule. My code successfully tracks logical cycles by advancing the `slow` index by one link (`slow = pointer[slow]`) while chasing it with a `fast` index moving two links at a time (`fast = pointer[pointer[fast]]`). ## 📊 Performance & Architecture Trade-offs Building an array-based linked list serves as a classic low-level optimization strategy. Below is how this architecture weighs out compared to standard pointer-based alternatives: ### Pros * **High Cache Locality:** Because all node data resides within a contiguous block of array memory, the CPU can load it into its ultra-fast cache line instantly. This completely avoids the latency associated with real pointers scattering data across different RAM locations. * **Zero Memory Leaks:** By avoiding `malloc`, I eliminated the risk of system crashes from un-freed heap allocations. Memory clean-up is completely handled automatically when the program exits. * **Instant Serialization:** This structure is immediately ready to be written directly to a binary file or sent over a network. Because it relies on static array indices rather than real RAM addresses, the pointers remain completely valid across different systems and execution runs. ### Cons * **Static Size Ceiling:** The maximum capacity of the list is permanently bound to the initialized array size. It cannot dynamically scale without allocating a brand new block of memory. * **Manual Allocation Overhead:** Without native memory allocation handling, I had to implement manual internal logic to keep track of vacant array slots during structural mutations. * **Memory Fragmentation & Waste:** Allocating a large array size ahead of time wastes substantial system memory if only a fraction of those slots are actively storing data. ## 🧠 Core Takeaway This project reinforced that data structures are entirely abstract concepts rather than rigid syntax rules. Building functional linked lists and cycle detection mechanisms requires no objects, pointers, or high-level abstractions—only an isolated data pool, a logical map, and standard arithmetic logic to navigate between them.