{"id":21725884,"url":"https://github.com/jakubtomsu/vmem","last_synced_at":"2025-08-27T01:44:15.657Z","repository":{"id":154415285,"uuid":"621787773","full_name":"jakubtomsu/vmem","owner":"jakubtomsu","description":"A cross-platform single-header C library for managing virtual memory. Currently for Windows and Linux.","archived":false,"fork":false,"pushed_at":"2023-08-15T15:30:04.000Z","size":233,"stargazers_count":23,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-12T22:54:36.261Z","etag":null,"topics":["c","cpp","cross-platform","gamedev","lightweight","memory-management","single-header","stb-style"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jakubtomsu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2023-03-31T11:42:42.000Z","updated_at":"2025-02-13T18:27:16.000Z","dependencies_parsed_at":null,"dependency_job_id":"f39b48d6-6b2e-451e-b22c-2d4dcf395e5c","html_url":"https://github.com/jakubtomsu/vmem","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jakubtomsu/vmem","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jakubtomsu%2Fvmem","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jakubtomsu%2Fvmem/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jakubtomsu%2Fvmem/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jakubtomsu%2Fvmem/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jakubtomsu","download_url":"https://codeload.github.com/jakubtomsu/vmem/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jakubtomsu%2Fvmem/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272277492,"owners_count":24905502,"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-26T02:00:07.904Z","response_time":60,"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":["c","cpp","cross-platform","gamedev","lightweight","memory-management","single-header","stb-style"],"created_at":"2024-11-26T03:20:02.291Z","updated_at":"2025-08-27T01:44:15.609Z","avatar_url":"https://github.com/jakubtomsu.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 💾 vmem.h 0.2\nA simple [STB-style](https://github.com/nothings/stb/blob/master/docs/stb_howto.txt) cross-platform C/C++ library for managing virtual memory.\n\n## Usage\nDefine `VMEM_IMPLEMENTATION` in only *one* C or C++ source file before including `vmem.h` to create the implementation.\n\ni.e. one file should look like this:\n```c\n#include ...\n#define VMEM_IMPLEMENTATION\n#include \"vmem.h\"\n```\nAnd all other files like this:\n```c\n#include ...\n#include \"vmem.h\"\n```\nAnd then you can use the public API. For example:\n```c\nconst int size = 1024 * 1024;\n// Allocate a block of virtual addresses. Note: you can't use this memory *yet*.\nvoid* ptr = vmem_alloc(size);\n// Mark some memory as ready to use.\nvmem_commit(ptr, 2048);\n\n// do something with the data, now you can use bytes in [0..\u003c2048]\n\n// When you don't need the whole memory block you can dealloc it.\n// To just mark it as unused, use `vmem_decommit` instead.\nvmem_dealloc(ptr, size);\n```\n\n## Features\n- Reserving, committing, decommiting and releasing memory\n- Page protection levels\n- Querying page size and allocation granularity\n- Memory usage status (total physical memory, available physical memory)\n- Address math utilities - aligning forwards, backwards, checking alignment\n- Arena allocation, see [Arena](#arena)\n\n## Supported platforms\n- Windows\n- Linux\n\nI would also like to add support for Mac, iOS and Android.\nGame consoles aren't supported, you will need to implement the platform backends on your own.\n\n## Dependencies\nThere are zero dependencies apart from the C standard library.\n\n## Arena\nArena is a bump allocator on a linear block of memory.\nWhen working with virtual memory, only the used part of the arena stays commited.\n\nYou can read more about advantages of arenas in [this blog post by Ryan Fleury](https://www.rfleury.com/p/untangling-lifetimes-the-arena-allocator).\n\nExample usage:\n```c\nVMemArena arena = vmem_arena_init_alloc(1024 * 1024); // Allocate an arena.\nvmem_arena_set_commited(\u0026arena, 32 * sizeof(int); // Commit part of the arena.\nfor(int i = 0; i \u003c 32; i++) {\n    *(int*)arena.mem = i;\n}\nvmem_arena_deinit_dealloc(\u0026arena); // Free the arena memory.\n```\n\n## Samples\nThe [samples/](samples/) folder contains a number of containers built using arena allocation.\n\nNote: currently the samples are mostly WIP, there will be more in the future.\n\nTests for the samples are in [tests/samples_test.cpp](tests/samples_test.cpp)\n\n## Tests\nTests use the [utest.h](https://github.com/sheredom/utest.h) library.\nYou can find all the vmem.h tests in [tests/vmem_test.c](tests/vmem_test.c).\n\n### Build tests\n```bash\n# Note: you can replace clang with 'gcc', 'zig cc' etc.\nclang tests/test.c -o test.exe\n# Other options\nclang++ -x c++ test/test.c -o test.exe -Wall -Werror -fsanitize=address,undefined -std=c++20\nclang test/test.c -o test.exe -Wall -Werror -fsanitize=address,undefined -std=c99\n```\nOr in `x64 Developer Command Prompt` on windows, using MSVC:\n```bash\ncl vmem_test.cpp /Fevmem_test.exe\n```\n\n## Error mangement\nIf a function fails, it returns a `VMemResult_Error` (which is 0/false).\nYou can get a string message about the error reason by calling `vmem_get_error_message`.\n\nBut by default, each error calls `assert(0)` from C standard library before returning.\nTo change/disable this behavior, you can `#define VMEM_ON_ERROR(opt_string) ...`.\n\nExample of dealing with errors:\n```c\n#define VMEM_ON_ERROR(opt_string) // Disable the default assertion\n#define VMEM_IMPLEMENTATION\n#include \"vmem.h\"\n#include \u003cstdio.h\u003e // printf\n\nint main() {\n    if(!vmem_dealloc(0, 0)) {\n        printf(\"vmem_dealloc failed with message: %s\\n\", vmem_get_error_message());\n        // Handle the error ...\n    }\n    return 0;\n}\n```\n\n## Compile-time options\n#define | Description\n------- | -----------\nVMEM_IMPLEMENTATION       | Instantiate the library implementation in the current source file.\nVMEM_FUNC                 | Specifiers for all API functions. E.g. you can mark all functions static with `#define VMEM_FUNC static`\nVMEM_INLINE               | Inline qualifier for short static functions defined in the header. Defined to platform-specific inline or forceinline specifier.\nVMEM_ON_ERROR(opt_string) | Called when an error is encountered. By default this just calls `assert(0)`. You can disable it with `#define VMEM_ON_ERROR(opt_string)`.\nVMEM_NO_ERROR_MESSAGES    | Disables all error messages. When you call `vmem_get_error_message` it gives you just `\u003cError messages disabled\u003e`.\nVMEM_NO_ERROR_CHECKING    | Completely disables ***all*** error checking. This might be very unsafe.\n\n\n## Language support\n- C99\n- C11\n- C++11\n- C++14\n- C++17\n- C++20\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjakubtomsu%2Fvmem","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjakubtomsu%2Fvmem","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjakubtomsu%2Fvmem/lists"}