{"id":38232603,"url":"https://github.com/j-obog/heap-sim","last_synced_at":"2026-01-17T01:01:40.218Z","repository":{"id":130264420,"uuid":"375682579","full_name":"J-Obog/heap-sim","owner":"J-Obog","description":"C++ program aimed to provide a high-level view of what's going on under the hood when you do pointer operations.","archived":false,"fork":false,"pushed_at":"2021-12-24T04:35:17.000Z","size":209,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-01-30T07:44:49.290Z","etag":null,"topics":["cpp","heap-memory","memory-management","modeling","simulation"],"latest_commit_sha":null,"homepage":"","language":"C++","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/J-Obog.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}},"created_at":"2021-06-10T12:03:03.000Z","updated_at":"2023-04-12T18:00:21.000Z","dependencies_parsed_at":"2023-03-29T20:37:27.672Z","dependency_job_id":null,"html_url":"https://github.com/J-Obog/heap-sim","commit_stats":{"total_commits":38,"total_committers":2,"mean_commits":19.0,"dds":0.02631578947368418,"last_synced_commit":"e0fea6ffd65c98b62d4dfdc67a30ea01074a5515"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/J-Obog/heap-sim","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/J-Obog%2Fheap-sim","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/J-Obog%2Fheap-sim/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/J-Obog%2Fheap-sim/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/J-Obog%2Fheap-sim/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/J-Obog","download_url":"https://codeload.github.com/J-Obog/heap-sim/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/J-Obog%2Fheap-sim/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28490904,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-17T00:50:05.742Z","status":"ssl_error","status_checked_at":"2026-01-17T00:43:11.982Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["cpp","heap-memory","memory-management","modeling","simulation"],"created_at":"2026-01-17T01:01:39.186Z","updated_at":"2026-01-17T01:01:40.045Z","avatar_url":"https://github.com/J-Obog.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Heap-Sim\n\nC++ program aimed to provide a high-level view of what's going on under the hood when you do pointer operations.\n\n## Usage\n\nCompile all files located int the src/ directory and link it your local project.\n\nMake sure to include the main header:\n\n```cpp\n#include \"heap.hpp\"\n```\n\nor\n\n```cpp\n#include \u003cheap.hpp\u003e\n```\n\n## Features\n\nKey features of Heap-Sim:\n\n- customizable size of memory\n- hex dump that's colorized to show which blocks are allocated\n- allocate variable sizes of memory\n- deallocate memory (remember, you are your own garbage collector)\n- retrieve and modify allocated data\n- This library provides the basic features that you get out of regular C++ pointers and like such, it is important that you remember to delete them when you are finished using them. We will go over how you can use declare and use pointers in your own application.\n\n---\n\n# Tutorial\n\nUsing Heap-Sim is straight-forward. Your application will boil down to these steps:\n\n1. Initializing the heap\n2. Declaring pointers\n3. Setting memory\n4. Getting memory\n5. Deleting pointers\n\n## Initializing the heap\n\nYou can initialize the heap memory like so\n\n```cpp\nHeapMem my_mem;\n```\n\nThis method creates a zeroed-out array of memory that by default is 1 KB. Alternativley, if you want to specify the size of the memory you can do so like this\n\n```cpp\nHeapMem my_mem(256);\n```\n\nWhere the argument passed is the size of the memory in bytes. In our case, 256 bytes\n\n### Declaring pointers\n\nC++ pointers are essentially unsigned integers that hold some address to a location in memory. In Heap-Sim you can declare a pointer by declaring an integer and have it point to a valid block of memory like so\n\n```cpp\nint ptr = my_mem.alloc(4);\n```\n\nThe `alloc` method reserves enough memory for the specifed passed in and returns the index to the memory array where the allocated block starts. In our case, we are allocating 4 bytes of memory and holding the address to that block via the `ptr` variable.\n\nYou can set a pointer to `NULL` by initializing it to an address that is impossible to reach. The easiest way of doing this is by setting the pointer to some negative value like so\n\n```cpp\nint another_ptr = -1;\n```\n\nNow we have declared a pointer that cannot address a location in memory. This is great if you don't want to set it to a value and worry about how much memory you have to allocate if you dont have an immediate use for it.\n\n## Setting memory\n\nYou can set a block of memory like so\n\n```cpp\nmy_mem.memset(ptr, 322);\n```\n\nThe `memset` method stores a specified value into an address of memory. The first argument is the pointer to the location that the value should reside. The second argument is the value to be stored. In our case, we are storing the integer '322' into the address pointed at by the `ptr` variable.\n\n**Note** The validity of the pointer is checked before the memory is actually set. If the pointer isn't valid, the program will throw a `bad_ptr` exception.\n\n## Getting memory\n\nYou can get a block of memory like so\n\n```cpp\nmy_mem.memget(ptr);\n```\n\nThe `memget` method retrieves the data stored in a specified block of memory. The argument passed in is the pointer to the head of that block of memory.\n\n**Note** The validity of the pointer is checked before the memory is actually set. If the pointer isn't valid, the program will throw a `bad_ptr` exception.\n\n## Deleting pointers\n\nWhen you are finished using the pointer, you can delete it like so\n\n```cpp\nmy_mem.dealloc(ptr);\n```\n\nThe `dealloc` method zeroes out the memory that was previously allocated. It takes in a pointer as an argument a clears out the block of memory that it points to. If you have used pointers in C or C++ you know that great power comes with great responsibility so it is important that you deallocate memory after you have finished using it. Failing to do so will cause memory leaks and your program will take a massive performance hit.\n\n**Note** The validity of the pointer is checked before the memory is actually deallocated. If the pointer isn't valid, the program will throw a `bad_ptr` exception.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fj-obog%2Fheap-sim","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fj-obog%2Fheap-sim","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fj-obog%2Fheap-sim/lists"}