├── .github ├── LICENSE └── README.md ├── mem └── mem.cppm /.github/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2025 Kris Jusiak 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.github/README.md: -------------------------------------------------------------------------------- 1 | ../mem -------------------------------------------------------------------------------- /mem: -------------------------------------------------------------------------------- 1 | // 26 | [Overview](#Overview) / [API](#API) / [FAQ](#FAQ) / [Resources](#Resources) 27 | 28 | ## `mem`: Memory Allocator library 29 | 30 | [![MIT Licence](http://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/license/mit) 31 | [![Version](https://img.shields.io/github/v/release/qlibs/mem)](https://github.com/qlibs/mem/releases) 32 | [![Build](https://img.shields.io/badge/build-green.svg)](https://godbolt.org/z/Yh6r9h9Pf) 33 | [![Try it online](https://img.shields.io/badge/try%20it-online-blue.svg)](https://godbolt.org/z/WdaTrqrxK) 34 | 35 | > [https://en.wikipedia.org/wiki/Allocator_C++](https://en.wikipedia.org/wiki/Allocator_(C%2B%2B)) 36 | 37 | ### Features 38 | 39 | - Single header (https://raw.githubusercontent.com/qlibs/mem/main/mem) / C++20 module (https://raw.githubusercontent.com/qlibs/mem/main/mem.cppm) 40 | - [C++23](https://eel.is/c++draft/allocator.requirements) standard compliant [API](#api) 41 | - Verifies itself upon `include/import` (can be disabled with `-DNTEST` - see [FAQ](#faq)) 42 | 43 | ### Requirements 44 | 45 | - C++20+ ([clang++12+, g++11+](https://en.cppreference.com/w/cpp/compiler_support)) / [`Linux`](https://en.wikipedia.org/wiki/Linux)\* / [`numactl`](https://github.com/numactl/numactl)\* 46 | 47 | ### Overview 48 | 49 | ```cpp 50 | import mem; 51 | 52 | int main() { 53 | static_assert(mem::allocator_like>); 54 | static_assert(mem::allocator_like>); 55 | static_assert(mem::allocator_like>); 56 | static_assert(mem::allocator_like>); 57 | static_assert(mem::allocator_like>); 58 | static_assert(mem::allocator_like>); 59 | 60 | { 61 | std::vector> v{}; 62 | std::vector> v{}; 63 | // echo 20 > /proc/sys/vm/nr_hugepages 64 | std::vector> v{}; 65 | // echo always > /sys/kernel/mm/transparent_hugepage/hugepages-2048kB/enabled 66 | std::vector> v{}; 67 | // -lnuma # requires libnuma-dev 68 | std::vector> v{}; 69 | } 70 | } 71 | ``` 72 | 73 | ### API 74 | 75 | > - https://github.com/qlibs/mem/blob/main/mem.cppm 76 | 77 | ### FAQ 78 | 79 | > - How to disable running tests at compile-time?
80 | > When `-DNTEST` is defined static_asserts tests wont be executed upon inclusion. 81 | > Note: Use with caution as disabling tests means that there are no gurantees upon inclusion that given compiler/env combination works as expected. 82 | > 83 | > - Similar projects?
84 | > [std::pmr](https://en.cppreference.com/w/cpp/header/memory) 85 | 86 | ### Resources 87 | 88 | > `std::allocator` 89 | > - https://eel.is/c++draft/allocator.requirements 90 | > - https://en.cppreference.com/w/cpp/memory/allocator 91 | 92 | > **Transparent Huge Pages** 93 | > - https://www.kernel.org/doc/html/latest/admin-guide/mm/transhuge.html 94 | > - https://man7.org/linux/man-pages/man2/madvise.2.html 95 | > - https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/6/html/performance_tuning_guide/s-memory-transhuge 96 | 97 | > **Huge Pages** 98 | > - https://www.kernel.org/doc/html/latest/admin-guide/mm/hugetlbpage.html 99 | > - https://www.man7.org/linux/man-pages/man2/mmap.2.html 100 | > - https://www.intel.com/content/www/us/en/docs/programmable/683840/1-2-1/enabling-hugepages.html 101 | > - https://github.com/libhugetlbfs/libhugetlbfs 102 | > - https://wiki.debian.org/Hugepages 103 | 104 | > **Non Uniform Memory Access** 105 | > - https://en.wikipedia.org/wiki/Non-uniform_memory_access 106 | > - https://man7.org/linux/man-pages/man3/numa.3.html 107 | > - https://www.intel.com/content/www/us/en/developer/articles/technical/use-intel-quickassist-technology-efficiently-with-numa-awareness.html 108 | 109 | ### License 110 | 111 | > - [MIT](LICENSE) 112 | 113 |