{"id":13648684,"url":"https://github.com/rustwasm/wee_alloc","last_synced_at":"2025-05-14T21:07:24.573Z","repository":{"id":39873523,"uuid":"118973621","full_name":"rustwasm/wee_alloc","owner":"rustwasm","description":"The Wasm-Enabled, Elfin Allocator","archived":false,"fork":false,"pushed_at":"2023-02-28T17:54:02.000Z","size":288,"stargazers_count":689,"open_issues_count":28,"forks_count":48,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-05-08T00:03:30.015Z","etag":null,"topics":["allocator","rust","rust-wasm","wasm"],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rustwasm.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","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}},"created_at":"2018-01-25T22:10:56.000Z","updated_at":"2025-05-07T17:18:14.000Z","dependencies_parsed_at":"2024-06-18T15:25:38.234Z","dependency_job_id":"a1b4abc7-4314-4931-9321-e0a856dbf090","html_url":"https://github.com/rustwasm/wee_alloc","commit_stats":{"total_commits":112,"total_committers":18,"mean_commits":6.222222222222222,"dds":0.4196428571428571,"last_synced_commit":"e7f33c28fcf7d197f2d84ab00acd8518643371dd"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rustwasm%2Fwee_alloc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rustwasm%2Fwee_alloc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rustwasm%2Fwee_alloc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rustwasm%2Fwee_alloc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rustwasm","download_url":"https://codeload.github.com/rustwasm/wee_alloc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254227612,"owners_count":22035669,"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","rust","rust-wasm","wasm"],"created_at":"2024-08-02T01:04:27.336Z","updated_at":"2025-05-14T21:07:19.562Z","avatar_url":"https://github.com/rustwasm.png","language":"Rust","funding_links":[],"categories":["Rust","Libraries"],"sub_categories":["Allocation and Memory Management"],"readme":"\u003cdiv align=\"center\"\u003e\n\n  \u003ch1\u003e\u003ccode\u003ewee_alloc\u003c/code\u003e\u003c/h1\u003e\n\n  \u003cstrong\u003eThe \u003cu\u003eW\u003c/u\u003easm-\u003cu\u003eE\u003c/u\u003enabled, \u003cu\u003eE\u003c/u\u003elfin Allocator\u003c/strong\u003e\n\n  \u003cp\u003e\n    \u003ca href=\"https://travis-ci.org/rustwasm/wee_alloc\"\u003e\u003cimg src=\"https://img.shields.io/travis/rustwasm/wee_alloc.svg?style=flat-square\" alt=\"Build Status\" /\u003e\u003c/a\u003e\n    \u003ca href=\"https://ci.appveyor.com/project/fitzgen/wee-alloc/branch/master\"\u003e\u003cimg src=\"https://img.shields.io/travis/rustwasm/wee_alloc.svg?style=flat-square\" alt=\"Build Status\" /\u003e\u003c/a\u003e\n    \u003ca href=\"https://crates.io/crates/wee_alloc\"\u003e\u003cimg src=\"https://img.shields.io/crates/v/wee_alloc.svg?style=flat-square\" alt=\"Crates.io version\" /\u003e\u003c/a\u003e\n    \u003ca href=\"https://crates.io/crates/wee_alloc\"\u003e\u003cimg src=\"https://img.shields.io/crates/d/wee_alloc.svg?style=flat-square\" alt=\"Download\" /\u003e\u003c/a\u003e\n    \u003ca href=\"https://docs.rs/wee_alloc\"\u003e\u003cimg src=\"https://img.shields.io/badge/docs-latest-blue.svg?style=flat-square\" alt=\"docs.rs docs\" /\u003e\u003c/a\u003e\n  \u003c/p\u003e\n\n  \u003ch3\u003e\n    \u003ca href=\"https://docs.rs/wee_alloc\"\u003eAPI Docs\u003c/a\u003e\n    \u003cspan\u003e | \u003c/span\u003e\n    \u003ca href=\"https://github.com/rustwasm/wee_alloc/blob/master/CONTRIBUTING.md\"\u003eContributing\u003c/a\u003e\n    \u003cspan\u003e | \u003c/span\u003e\n    \u003ca href=\"https://discordapp.com/channels/442252698964721669/443151097398296587\"\u003eChat\u003c/a\u003e\n  \u003c/h3\u003e\n\n  \u003csub\u003eBuilt with 🦀🕸 by \u003ca href=\"https://rustwasm.github.io/\"\u003eThe Rust and WebAssembly Working Group\u003c/a\u003e\u003c/sub\u003e\n\u003c/div\u003e\n\n\n### About\n\n`wee_alloc`: The **W**asm-**E**nabled, **E**lfin Allocator.\n\n- **Elfin, i.e. small:** Generates less than a kilobyte of uncompressed\n  WebAssembly code. Doesn't pull in the heavy panicking or formatting\n  infrastructure. `wee_alloc` won't bloat your `.wasm` download size on the Web.\n\n- **WebAssembly enabled:** Designed for the `wasm32-unknown-unknown` target and\n  `#![no_std]`.\n\n`wee_alloc` is focused on targeting WebAssembly, producing a small `.wasm` code\nsize, and having a simple, correct implementation. It is geared towards code\nthat makes a handful of initial dynamically sized allocations, and then performs\nits heavy lifting without any further allocations. This scenario requires *some*\nallocator to exist, but we are more than happy to trade allocation performance\nfor small code size. In contrast, `wee_alloc` would be a poor choice for a\nscenario where allocation is a performance bottleneck.\n\nAlthough WebAssembly is the primary target, `wee_alloc` also has an `mmap` based\nimplementation for unix systems, a `VirtualAlloc` implementation for Windows,\nand a static array-based backend for OS-independent environments. This enables\ntesting `wee_alloc`, and code using `wee_alloc`, without a browser or\nWebAssembly engine.\n\n`wee_alloc` compiles on stable Rust 1.33 and newer.\n\n- [Using `wee_alloc` as the Global Allocator](#using-wee_alloc-as-the-global-allocator)\n- [`cargo` Features](#cargo-features)\n- [Implementation Notes and Constraints](#implementation-notes-and-constraints)\n- [License](#license)\n- [Contribution](#contribution)\n\n### Using `wee_alloc` as the Global Allocator\n\n```rust\nextern crate wee_alloc;\n\n// Use `wee_alloc` as the global allocator.\n#[global_allocator]\nstatic ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;\n```\n\n### `cargo` Features\n\n- **size_classes**: On by default. Use size classes for smaller allocations to\n  provide amortized *O(1)* allocation for them. Increases uncompressed `.wasm`\n  code size by about 450 bytes (up to a total of ~1.2K).\n\n- **extra_assertions**: Enable various extra, expensive integrity assertions and\n  defensive mechanisms, such as poisoning freed memory. This incurs a large\n  runtime overhead. It is useful when debugging a use-after-free or `wee_alloc`\n  itself.\n\n- **static_array_backend**: Force the use of an OS-independent backing\n  implementation with a global maximum size fixed at compile time.  Suitable for\n  deploying to non-WASM/Unix/Windows `#![no_std]` environments, such as on\n  embedded devices with esoteric or effectively absent operating systems. The\n  size defaults to 32 MiB (33554432 bytes), and may be controlled at build-time\n  by supplying an optional environment variable to cargo,\n  `WEE_ALLOC_STATIC_ARRAY_BACKEND_BYTES`. Note that this feature requires\n  nightly Rust.\n\n- **nightly**: Enable usage of nightly-only Rust features, such as implementing\n  the `Alloc` trait (not to be confused with the stable `GlobalAlloc` trait!)\n\n### Implementation Notes and Constraints\n\n- `wee_alloc` imposes two words of overhead on each allocation for maintaining\n  its internal free lists.\n\n- Deallocation is an *O(1)* operation.\n\n- `wee_alloc` will never return freed pages to the WebAssembly engine /\n  operating system. Currently, WebAssembly can only grow its heap, and can never\n  shrink it. All allocated pages are indefinitely kept in `wee_alloc`'s internal\n  free lists for potential future allocations, even when running on unix\n  targets.\n\n- `wee_alloc` uses a simple, first-fit free list implementation. This means that\n  allocation is an *O(n)* operation.\n\n  Using the `size_classes` feature enables extra free lists dedicated to small\n  allocations (less than or equal to 256 words). The size classes' free lists\n  are populated by allocating large blocks from the main free list, providing\n  amortized *O(1)* allocation time. Allocating from the size classes' free lists\n  uses the same first-fit routines that allocating from the main free list does,\n  which avoids introducing more code bloat than necessary.\n\nFinally, here is a diagram giving an overview of `wee_alloc`'s implementation:\n\n```\n+------------------------------------------------------------------------------+\n| WebAssembly Engine / Operating System                                        |\n+------------------------------------------------------------------------------+\n                   |\n                   |\n                   | 64KiB Pages\n                   |\n                   V\n+------------------------------------------------------------------------------+\n| Main Free List                                                               |\n|                                                                              |\n|          +------+     +------+     +------+     +------+                     |\n| Head --\u003e | Cell | --\u003e | Cell | --\u003e | Cell | --\u003e | Cell | --\u003e ...             |\n|          +------+     +------+     +------+     +------+                     |\n|                                                                              |\n+------------------------------------------------------------------------------+\n                   |                                    |            ^\n                   |                                    |            |\n                   | Large Blocks                       |            |\n                   |                                    |            |\n                   V                                    |            |\n+---------------------------------------------+         |            |\n| Size Classes                                |         |            |\n|                                             |         |            |\n|             +------+     +------+           |         |            |\n| Head(1) --\u003e | Cell | --\u003e | Cell | --\u003e ...   |         |            |\n|             +------+     +------+           |         |            |\n|                                             |         |            |\n|             +------+     +------+           |         |            |\n| Head(2) --\u003e | Cell | --\u003e | Cell | --\u003e ...   |         |            |\n|             +------+     +------+           |         |            |\n|                                             |         |            |\n| ...                                         |         |            |\n|                                             |         |            |\n|               +------+     +------+         |         |            |\n| Head(256) --\u003e | Cell | --\u003e | Cell | --\u003e ... |         |            |\n|               +------+     +------+         |         |            |\n|                                             |         |            |\n+---------------------------------------------+         |            |\n                      |            ^                    |            |\n                      |            |                    |            |\n          Small       |      Small |        Large       |      Large |\n          Allocations |      Frees |        Allocations |      Frees |\n                      |            |                    |            |\n                      |            |                    |            |\n                      |            |                    |            |\n                      |            |                    |            |\n                      |            |                    |            |\n                      V            |                    V            |\n+------------------------------------------------------------------------------+\n| User Application                                                             |\n+------------------------------------------------------------------------------+\n```\n\n### License\n\nLicensed under the [Mozilla Public License 2.0](https://www.mozilla.org/en-US/MPL/2.0/).\n\n[TL;DR?](https://choosealicense.com/licenses/mpl-2.0/)\n\n\u003e Permissions of this weak copyleft license are conditioned on making available\n\u003e source code of licensed files and modifications of those files under the same\n\u003e license (or in certain cases, one of the GNU licenses). Copyright and license\n\u003e notices must be preserved. Contributors provide an express grant of patent\n\u003e rights. However, a larger work using the licensed work may be distributed\n\u003e under different terms and without source code for files added in the larger\n\u003e work.\n\n### Contribution\n\nSee\n[CONTRIBUTING.md](https://github.com/rustwasm/wee_alloc/blob/master/CONTRIBUTING.md)\nfor hacking!\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frustwasm%2Fwee_alloc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frustwasm%2Fwee_alloc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frustwasm%2Fwee_alloc/lists"}