{"id":18736892,"url":"https://github.com/bitwizeshift/bit-memory","last_synced_at":"2025-04-12T19:32:05.188Z","repository":{"id":81485334,"uuid":"80258673","full_name":"bitwizeshift/bit-memory","owner":"bitwizeshift","description":"A hobby library for c++ memory management","archived":false,"fork":false,"pushed_at":"2018-05-17T04:24:29.000Z","size":2249,"stargazers_count":9,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-26T14:01:46.800Z","etag":null,"topics":["allocator","c-plus-plus-14","cpp14","memory-allocator","memory-management","modern-cpp"],"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/bitwizeshift.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}},"created_at":"2017-01-28T00:58:51.000Z","updated_at":"2024-02-08T05:39:20.000Z","dependencies_parsed_at":null,"dependency_job_id":"7def3e58-cc48-4204-aa0d-571d2d9ae4cf","html_url":"https://github.com/bitwizeshift/bit-memory","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitwizeshift%2Fbit-memory","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitwizeshift%2Fbit-memory/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitwizeshift%2Fbit-memory/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitwizeshift%2Fbit-memory/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bitwizeshift","download_url":"https://codeload.github.com/bitwizeshift/bit-memory/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248621216,"owners_count":21134777,"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","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":["allocator","c-plus-plus-14","cpp14","memory-allocator","memory-management","modern-cpp"],"created_at":"2024-11-07T15:22:52.539Z","updated_at":"2025-04-12T19:32:05.182Z","avatar_url":"https://github.com/bitwizeshift.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `bit::memory` Memory library\n\n[![Build Status](https://travis-ci.org/bitwizeshift/bit-memory.svg?branch=master)](https://travis-ci.org/bitwizeshift/bit-memory)\n[![Build status](https://ci.appveyor.com/api/projects/status/ou5sraydky6tjxv9?svg=true)](https://ci.appveyor.com/project/bitwizeshift/bit-memory)\n[![Github Issues](https://img.shields.io/github/issues/bitwizeshift/bit-memory.svg)](http://github.com/bitwizeshift/bit-memory/issues)\n[![Tested Compilers](https://img.shields.io/badge/compilers-gcc%20%7C%20clang%20%7C%20msvc-blue.svg)](#tested-compilers)\n[![Documentation](https://img.shields.io/badge/docs-doxygen-blue.svg)](http://bitwizeshift.github.io/bit-memory)\n[![GitHub License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/bitwizeshift/bit-memory/blob/master/LICENSE.md)\n[![Github Releases](https://img.shields.io/github/release/bitwizeshift/bit-memory.svg)](https://github.com/bitwizeshift/bit-memory/releases)\n\n## What is `bit::memory`?\n\nThis is an all-purpose memory management library. The primary emphasis on this library revolves around the memory allocators in the library,\ndesigned to be as lightweight and efficient as possible. Custom C++ _logical_ concepts are designed and adhered to strictly within this library. Sadly these are not (yet) `C++20` or `C++ Concepts TS` concepts since they are not standardized.\n\nAdditionally, this library offers utilities for the following concerns:\n\n- Standard Adapters: Adapter functionality between this library's `Allocator` concepts and the C++ standard library Allocator\n- Endianness: Detects host machine endianness, and offers casting with `endian_cast` and `endian_swap` utilities\n- Unaligned Access: Utilities for loading unaligned data in a standard-compliant manner\n- Virtual Memory: Functionality for reserving and committing virtual memory pages in a cross-platform way (MacOS,Linux, and Windows)\n- Aligned Memory: Functionality for allocating over-aligned memory\n\nThis library defines a variety of `BlockAllocator`s and `Allocator`s -- and is extendable through user-defined custom types that\nconform to the concepts defined here.\n\n## Differences from Standard Allocators\n\nThe `Allocator` concept in this library differs from the C++ standard's allocators in a few ways\n\n### 1. Allocators are heterogeneous\n\nThe C++ Standard Library's `Allocator` concept defines every `Allocator` to be homogeneous in its allocations; always allocating\na specific type `T`, and only converting to different allocators using `rebind`. This offers some level of optimizations, since\nall allocations are of fixed size; but also can cause large amounts of code duplication due to the requirement of templates to\nproduce different instances of the same type, all based on type `T`.\n\nAs a result, this library uses the SGI and HP approach of only allocating by `void*`, rather than by a given type. A wrapper\ntype called `std_allocator_wrapper` exists to wrap the given allocator in a manner that works with C++ standard containers.\n\n### 2. Allocators support alignment\n\nSince the C++ Standard Library's `Allocator` only cares about the type `T` being allocated, there is no generalized support\nfor over-aligning types.\n\nThe `Allocator` concept in this library _requires_ the presence of an alignment argument in order to work properly (although\nthis argument may be ignored in certain implementations).\n\n### 3. Allocators require `try_allocate` rather than `allocate`\n\nThis is a subtle difference. The C++ Standard Library's `allocate(...)` function is free to throw exceptions on failure; leaving\nnon-throwing allocators up to an implementation's discretion. The `Allocator` concept in this library requires `try_allocate`, which\nmay return a null pointer on failure and must be non-throwing.\n\nThis allows for greater composition with other allocators, since an allocator that fails to allocate can be queried without requiring\n`try`/`catch` statements (e.g. for fallback allocators)\n\nThe optional `allocate` function _may_ throw. If this is not defined, then `allocator_traits\u003cAllocator\u003e::allocate(...)` defines a custom\none that -- on failure -- calls a global out-of-memory handler.\n\n### 4. Allocator info\n\nThe Allocator concept in this library optionally supports a member function named `info()` that returns an `allocator_info` object.\nThis object is used for _naming_ the allocator so that it can be uniquely identified in case an error handler is called.\n\n## Using `bit::memory`\n\n### Building \u0026 Installing\n\nBuilding `bit::memory` is simple, and only requires a CMake version greater than 3.1, and a compatible compiler.\n\nFist, make a directory to build the library in, then build with CMake\n\n```bash\nmkdir build\ncd build\n\ncmake . -DBIT_MEMORY_BUILD_UNIT_TESTS=Off -DBIT_MEMORY_BUILD_INDEPENDENCE_TESTS=Off  # ... any additional toolchain parameters ...\ncmake --build .\n```\n\nOmitting the `-DBIT_MEMORY_BUILD_UNIT_TESTS=Off` will build unit tests; likewise `DBIT_MEMORY_BUILD_INDEPENDENCE_TESTS=Off` will\nbuild header-independence checks (building each header independently to ensure there are no header-order based transitive dependencies).\n\nTo install, run:\n\n```bash\ncmake --build . --target install\n```\n\nTo change the output directory of the installation, you can export `BIT_HOME` to install to a specific directory\n\n```bash\nexport BIT_HOME=/etc/bit\ncmake --build . --target install\n```\n\nwill install into `/etc/bit/`.\n\n### Through a `cmake` subdirectory\n\nClone/copy/subtree the contents of this repository to a subdirectory, and `add_subdirectory` the directory containing `bit::memory`.\n\nTo add a dependency to the library, just add `target_link_libraries(\u003cyour target\u003e [PUBLIC|INTERFACE|PRIVATE] bit::memory)`\n\n## \u003ca name=\"tested-compilers\"\u003e\u003c/a\u003eTested Compilers\n\nThe following compilers are currently being tested through continuous integration with [Travis](https://travis-ci.org/bitwizeshift/bit-memory) and [AppVeyor](https://ci.appveyor.com/project/bitwizeshift/bit-memory/)\n\nNote that `bit-memory` only works on compiler that provide proper conformance for c++14\n\n| Compiler              | Operating System                   |\n|-----------------------|------------------------------------|\n| g++ 6.3.0             | Ubuntu 14.04.3 TLS                 |\n| g++ 7.2.0             | Ubuntu 14.04.3 TLS                 |\n| clang++ 3.9.0         | Ubuntu 14.04.3 TLS                 |\n| clang++ 4.0.1         | Ubuntu 14.04.3 TLS                 |\n| clang++ 5.0           | Ubuntu 14.04.3 TLS                 |\n| g++ 7.2.0             | Ubuntu 14.04.3 TLS                 |\n| clang xcode 7.3       | Darwin Kernel 15.6.0 (OSX 10.11.6) |\n| clang xcode 8.0       | Darwin Kernel 15.6.0 (OSX 10.11.6) |\n| clang xcode 8.1       | Darwin Kernel 16.1.0 (OSX 10.12.1) |\n| clang xcode 8.2       | Darwin Kernel 16.1.0 (OSX 10.12.1) |\n| clang xcode 8.3       | Darwin Kernel 16.6.0 (OSX 10.12.5) |\n| clang xcode 9.0       | Darwin Kernel 16.7.0 (OSX 10.12.6) |\n| Visual Studio 2017    | Windows Server 2016 (x64)          |\n\n**Note:** Unfortunately, support for Visual Studio 2015 had to be dropped due to issues properly performing SFINAE\nwith some non-owning type-erased classes (`any_allocator` and `any_block_allocator`).\nIt has just not been worth the hassle to attempt to support a non-standards-conforming compiler. Fortunately,\nVisual Studios 2017 is still supported, and will continue to be.\n\n## \u003ca name=\"license\"\u003e\u003c/a\u003eLicense\n\n\u003cimg align=\"right\" src=\"http://opensource.org/trademarks/opensource/OSI-Approved-License-100x137.png\"\u003e\n\nThe class is licensed under the [MIT License](http://opensource.org/licenses/MIT):\n\nCopyright \u0026copy; 2018 Matthew Rodusek\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitwizeshift%2Fbit-memory","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbitwizeshift%2Fbit-memory","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitwizeshift%2Fbit-memory/lists"}