{"id":30430482,"url":"https://github.com/brendanddev/simulated-heap","last_synced_at":"2025-08-22T18:22:28.115Z","repository":{"id":310723751,"uuid":"1040984005","full_name":"brendanddev/simulated-heap","owner":"brendanddev","description":"A Java project that simulates manual memory management, similar to how low-level languages like C handle heap memory.","archived":false,"fork":false,"pushed_at":"2025-08-19T20:31:37.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-19T22:08:31.461Z","etag":null,"topics":["heap","java","memory-allocation","memory-management"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brendanddev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-08-19T19:59:31.000Z","updated_at":"2025-08-19T20:31:40.000Z","dependencies_parsed_at":"2025-08-19T22:08:34.110Z","dependency_job_id":"7a030eb9-c0c0-4318-a49f-1c81258b0000","html_url":"https://github.com/brendanddev/simulated-heap","commit_stats":null,"previous_names":["brendanddev/simulated-heap"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/brendanddev/simulated-heap","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brendanddev%2Fsimulated-heap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brendanddev%2Fsimulated-heap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brendanddev%2Fsimulated-heap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brendanddev%2Fsimulated-heap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brendanddev","download_url":"https://codeload.github.com/brendanddev/simulated-heap/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brendanddev%2Fsimulated-heap/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271680831,"owners_count":24802077,"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","status":"online","status_checked_at":"2025-08-22T02:00:08.480Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","java","memory-allocation","memory-management"],"created_at":"2025-08-22T18:22:24.078Z","updated_at":"2025-08-22T18:22:28.082Z","avatar_url":"https://github.com/brendanddev.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Simulated Heap \n\nA project that simulates **manual memory management**, similar to how low-level languages like C handle heap memory.  \nInstead of letting the JVM handle allocation and garbage collection automatically, this project demonstrates how a heap could be built and managed by hand.\n\n---\n\n## Features \n\n- **Custom Heap Simulation**: Backed by a simple `byte[]` array\n- **Memory Blocks**: Tracks allocated and free chunks of memory (`MemoryBlock` class)\n- **Manual Allocation (`malloc`)**: First-fit, Best-fit, Worst-fit, or Next-fit allocation strategies can be used to allocate memory blocks.\n- **Manual Deallocation (`free`)**: Supports freeing blocks and coalescing adjacent free blocks to reduce fragmentation.\n- **Simulated Pointers**: Each `MemoryBlock` can reference other blocks.\n- **Root Set Management**: `RootSet` tracks reachable memory blocks to prevent collection.\n- **Garbage Collection**: Implements a mark-and-sweep GC that frees unreachable memory while preserving reachable blocks.\n- **Heap Visualization**: `printHeap()` shows the current state of the heap for debugging.\n- **Garbage Collection Visualization**: `GCVisualizer` provides a graphical view of heap changes during GC cycles.\n- **Memory Alignment**:\n- **Demo Program**: `Main.java` runs a sequence of allocations/frees to show heap changes in action.  \n\n---\n\n## Installation\n1. Clone the repository:\n   ```bash\n   git clone \n   cd simulated-heap\n   ```\n\n2. Build the project using Maven:\n   ```bash\n   mvn clean compile\n   ```\n\n3. Run the demo program:\n   ```bash\n    mvn exec:java -Dexec.mainClass=\"brendanddev.Main\"\n    ```\n\n---\n\n## Project Structure\n\n```\nsimulated-heap/\n│\n├─ src/main/java/brendanddev/\n│   ├─ heap/                 # Core memory management\n│   │   ├─ SimulatedHeap.java\n│   │   ├─ MemoryBlock.java\n│   │   └─ AllocationStrategy.java\n│   │\n│   ├─ gc/                   # Garbage collection components\n│   │   ├─ GarbageCollector.java\n│   │   └─ RootSet.java\n│   │\n│   ├─ visualization/        # Visualization tools\n│   │   ├─ HeapVisualizer.java\n│   │   └─ GCVisualizer.java\n│   │\n│   └─ Main.java             # Demo entry point\n│\n├─ pom.xml\n└─ README.md\n```\n\n---\n\n## Example Usage  \n\n```java\nSimulatedHeap heap = new SimulatedHeap(32);\n\nint a = heap.malloc(8);   // allocate 8 bytes\nint b = heap.malloc(8);   // allocate another 8 bytes\nheap.printHeap();         // shows two allocated blocks + one free block\n\nheap.free(a);             // free the first 8-byte block\nheap.printHeap();\n\nint c = heap.malloc(4);   // allocate 4 bytes inside the first free region\nheap.printHeap();\n\nheap.free(b);             // free the second block\nheap.free(c);             // free the 4-byte block\nheap.printHeap();         // entire heap is free again\n\n// Demonstrate Garbage Collection\nRootSet rootSet = heap.getRootSet();\nrootSet.add(b);            // mark block 'b' as reachable\nGarbageCollector gc = new GarbageCollector(heap, rootSet);\ngc.collect();\nheap.printHeap();          // only reachable blocks remain allocated\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrendanddev%2Fsimulated-heap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrendanddev%2Fsimulated-heap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrendanddev%2Fsimulated-heap/lists"}