{"id":19541428,"url":"https://github.com/ickk/orderly-allocator","last_synced_at":"2025-04-26T17:30:47.775Z","repository":{"id":257698292,"uuid":"850462598","full_name":"ickk/orderly-allocator","owner":"ickk","description":"A super-simple soft-realtime allocator","archived":false,"fork":false,"pushed_at":"2025-02-06T09:20:33.000Z","size":34,"stargazers_count":7,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"dev","last_synced_at":"2025-04-02T08:16:13.332Z","etag":null,"topics":["allocator","real-time"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/orderly-allocator","language":"Rust","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/ickk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","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":"2024-08-31T20:50:25.000Z","updated_at":"2025-03-01T09:16:33.000Z","dependencies_parsed_at":"2024-09-18T06:19:14.230Z","dependency_job_id":"f4c061f3-bd15-47ea-9b43-130295e7c653","html_url":"https://github.com/ickk/orderly-allocator","commit_stats":null,"previous_names":["ickk/orderly-allocator"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ickk%2Forderly-allocator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ickk%2Forderly-allocator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ickk%2Forderly-allocator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ickk%2Forderly-allocator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ickk","download_url":"https://codeload.github.com/ickk/orderly-allocator/tar.gz/refs/heads/dev","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251025574,"owners_count":21524826,"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","real-time"],"created_at":"2024-11-11T03:10:28.022Z","updated_at":"2025-04-26T17:30:47.769Z","avatar_url":"https://github.com/ickk.png","language":"Rust","readme":"`orderly-allocator`\n===================\n[crates.io](https://crates.io/crates/orderly-allocator) |\n[docs.rs](https://docs.rs/orderly-allocator) |\n[github](https://github.com/ickk/orderly-allocator)\n\nA super-simple soft-realtime allocator for managing an external pool of memory.\n\nThis allocator stores its metadata separately from the memory it manages, so it\ncan be useful as a suballocator for a GPU buffer.\n\nA pair of BTrees is used to manage state internally, giving `orderly-allocator`\nworst-case O(log(n)) performance for `alloc` \u0026 `free`\\*. Uses a \"best-fit\"\nsearch strategy and coalesces immediately on `free`, resulting in low\nfragmentation.\n\nProvided functionality:\n- `alloc(size)`\n- `alloc_with_align(size, align)`\n- `free(allocation)`\n- `try_reallocate(allocation, new_size)` - grow/shrink an allocation in-place\n- `grow_capacity(additional)` - expand the allocator itself\n- `reset()` - free all allocations\n\nMetadata facilities:\n- `capacity()`\n- `is_empty()`\n- `largest_available()` - size of the biggest free region\n- `total_available()` - size of the sum of all free regions\n- `report_free_regions()` - iterator of free regions\n\n\n### Usage\n\nThis crate provides [`Allocator`] and [`Allocation`] which can be used to\nmanage any kind of buffer.\n\n```rust\nuse {\n  ::core::mem::{align_of, size_of},\n  ::orderly_allocator::{Allocation, Allocator},\n};\n\n// Create memory and allocator\nconst CAPACITY: u32 = 65_536;\nlet mut memory: Vec\u003cu8\u003e = vec![0; CAPACITY as usize];\nlet mut allocator = Allocator::new(CAPACITY);\n\n// An object to store\ntype Object = [u8; 16];\nlet object: Object = [\n  0x68, 0x65, 0x6C, 0x6C, 0x6F, 0x2C, 0x20, 0x6F,\n  0x72, 0x64, 0x65, 0x72, 0x6C, 0x79, 0x21, 0x0,\n];\n\n// Allocate some memory\nlet allocation = allocator.alloc_with_align(\n  size_of::\u003cObject\u003e() as u32,\n  align_of::\u003cObject\u003e() as u32,\n).unwrap();\n\n// Fill the allocation\nmemory[allocation.range()].copy_from_slice(\u0026object[..]);\n\n// Later, free the memory region\nallocator.free(allocation);\n```\n\n\n### `#![no_std]`\n\nThis crate works in a `no_std` context, however it requires the `alloc` crate\nfor the BTree implementation.\n\n\n### Future Work\n\n*The BTree implementation at the heart of `orderly-allocator` is simply the\nstandard library's `BTreeMap`/`BTreeSet`. This means the global-allocator is\nused to create new tree-nodes every now and then. For real-time graphics this\nis fine as the cost is amortised, and more importantly the I/O to actually\n*fill* the allocated memory is likely to be the far greater cost.\n\nIt would be possible to improve performance and turn this into a firm- or\nhard-realtime allocator by using a BTree implementation that pre-allocated\nnodes ahead of time.\n\n\n### Alternatives\n\nOther libraries in the ecosystem that serve a similar purpose:\n\n- [range-alloc] Generic range allocator, from the gfx-rs/wgpu project.\n- [offset-allocator] A Rust port of Sebastian Aaltonen's\n  [C++ package][sebbbi/OffsetAllocator] of the same name.\n\n[range-alloc]: https://crates.io/crates/range-alloc\n[offset-allocator]: https://crates.io/crates/offset-allocator\n[sebbbi/OffsetAllocator]: https://github.com/sebbbi/OffsetAllocator\n\n\nLicense\n-------\n\nThis crate is licensed under any of the [Apache license 2.0], or the\n[MIT license], or the [Zlib license] at your option.\n\n[Apache license 2.0]: ./LICENSE-APACHE\n[MIT license]: ./LICENSE-MIT\n[Zlib license]: ./LICENSE-ZLIB\n\n\n### Contribution\n\nUnless you explicitly state otherwise, any contributions you intentionally\nsubmit for inclusion in this work shall be licensed as above, without any\nadditional terms or conditions.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fickk%2Forderly-allocator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fickk%2Forderly-allocator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fickk%2Forderly-allocator/lists"}