{"id":13611727,"url":"https://github.com/shadyfennec/stupidalloc","last_synced_at":"2025-04-13T05:33:28.393Z","repository":{"id":178339906,"uuid":"661726941","full_name":"shadyfennec/stupidalloc","owner":"shadyfennec","description":"A stupid Rust memory allocator","archived":false,"fork":false,"pushed_at":"2023-12-29T20:22:54.000Z","size":50,"stargazers_count":191,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-03-14T17:33:11.229Z","etag":null,"topics":["memory-management","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shadyfennec.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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}},"created_at":"2023-07-03T14:03:56.000Z","updated_at":"2024-01-26T05:13:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"5662c7b0-ac74-46bc-80a6-06dcc3ba9f03","html_url":"https://github.com/shadyfennec/stupidalloc","commit_stats":null,"previous_names":["shadyfennec/stupidalloc"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shadyfennec%2Fstupidalloc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shadyfennec%2Fstupidalloc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shadyfennec%2Fstupidalloc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shadyfennec%2Fstupidalloc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shadyfennec","download_url":"https://codeload.github.com/shadyfennec/stupidalloc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248670513,"owners_count":21142896,"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":["memory-management","rust"],"created_at":"2024-08-01T19:02:02.181Z","updated_at":"2025-04-13T05:33:23.535Z","avatar_url":"https://github.com/shadyfennec.png","language":"Rust","readme":"# Stupid alloc - what if memory allocation was annoying\nMostly a weird exercise in how much you can make a memory allocator suck.\n\nThis allocator will create and open files to use as the allocation's data, through a memory map. If you enable the `interactive` feature, it will even prompt you for a file name every time\nthe program allocates something! Cool!\n\n\n## How to use it\ndon't\n\n## No but really how does one use this\nUsing `cargo add`:\n\n```shell\ncargo add stupidalloc\n```\n\nManually specifying the dependency in `Cargo.toml`:\n\n```toml\n[dependencies]\nstupidalloc = { version = \"0.2.1\" }\n```\n\n### The `interactive` feature\nThe crate comes with a feature, `interactive`, that will open confirmation and file picker dialog windows instead of silently opening and allocating memory. Enable it at your own risk,\nas sometimes dialogs are unavailable. This crate uses [`native-dialog`](https://crates.io/crates/native-dialog) for this feature.\n\n### Graphical interface\nThe `graphics` feature creates graphical windows that display memory contents as black or white pixels, representing the bits of the allocations! Click on each pixel to either set the bit (left click) or clear the bit (right click). You can easily modify memory contents this way!\n\nAdditionally, the `always-graphics` feature enables graphical windows for every single new allocation performed, and not just creation on-demand by the user.\n\nGraphical windows are created using the [`minifb`](https://crates.io/crates/minifb) crate.\n\nhttps://github.com/shadyfennec/stupidalloc/assets/68575248/b19790c7-bc9e-4a59-99c9-18d7e308739e\n\n### Logging\nThe `logging` crate creates companion logging files that record useful information about each allocation, using the familiar Markdown format. Useful for debugging!\n\n## Using the allocator\n- You can use it as the global allocator of your program, but it may lead to wonkiness and weird stuff like prompting for allocations before `main()` is executed!\n\n```rust\nuse stupidalloc::StupidAlloc;\n\n#[global_allocator]\nstatic GLOBAL: StupidAlloc = StupidAlloc;\n\nfn main() {\n    // ...\n}\n```\n\n- By using the [`allocator_api`](https://doc.rust-lang.org/beta/unstable-book/library-features/allocator-api.html) nightly feature, you can selectively\nallocate single objects with this allocator:\n\n```rust\n// Requires nightly\n#![feature(allocator_api)]\n\nuse stupidalloc::StupidAlloc;\n\nfn main() {\n    let normal_box = Box::new(1);\n\n    let stupid_box = Box::new_in(1, StupidAlloc);\n}\n```\n\nA cool usage is to stop the execution of your program (through your favourite `stdin` read) and then go look at the allocation files with a hex editor (might I recommend [Hexyl](https://github.com/sharkdp/hexyl)?)\n\nTo help you with that, the allocator exposes a few helper functions:\n- `StupidAlloc.state()` returns a `HashMap` where the key is the address of the memory map (and so the address of the allocated object), and the value is a `PathBuf` to the associated file.\n- `StupidAlloc` implements `fmt::Display`, so running `println!(\"{StupidAlloc}\")` will print a lovely summary of all the allocations currently being tracked.\n- `StupidAlloc.file_of(x)` will return the file associated to the linked object, if it exists. Obviously this only works with stuff allocated with the stupid allocator. An example of use:\n\n```rust\n// Still requires nightly\n#![feature(allocator_api)]\n\nuse stupidalloc::StupidAlloc;\n\nfn main() {\n    let stupid_box = Box::new_in(1, StupidAlloc);\n\n    // Since it's a Box\u003ci32\u003e, we need to pass \u0026i32 to the function to get the \n    // address of where the integer is.\n    let file = StupidAlloc.file_of(\u0026*stupid_box).unwrap();\n\n    // Go nuts with it!\n}\n```\n\nAnother cool usage is to be able to see how stuff is laid out in memory, without\nhaving to use memory viewers or complicated GDB syntax!\n\nFor example, ever wanted to see how a `Vec\u003cT\u003e` is organised in memory?\n\n```rust\nuse stupidalloc::StupidAlloc;\n\n#[global_allocator]\nstatic GLOBAL: StupidAlloc = StupidAlloc;\n\nfn main() {\n    let boxed_vec = Box::new(vec![1, 2, 3]);\n\n    println!(\"{}\", StupidAlloc.file_of(\u0026*boxed_vec).unwrap().display());\n\n    // Somehow pause execution\n}\n```\n\nThis program will print the path of the allocation file for the `Vec\u003cT\u003e` struct\n(and not the allocation for the data of the `Vec`, because then we'd only see\nthe numbers 1, 2, 3!). Open it in a hex viewer, and you can try and guess what\neach field is, and try to corroborate it with the [struct's definition](https://doc.rust-lang.org/stable/std/vec/struct.Vec.html).\nIf your system allows you to (I know Windows can be a bit restrictive), try and \nmodify the length and/or capacity fields and see what happens afterwards!\n\n## Disclaimers\n- I do not claim that this library is perfect and free of any fault. Here there be typos and mistakes and examples that I didn't test and don't work. Send an issue if something's wrong!\n- If you don't have file picker / file dialog capabilities (minimal i3 installation, TTY-only, ...), `interactivity` won't work. \n- Similarly, if you don't have a graphical environment altogether, `graphics` and `always-graphics` won't work either.\n- I only tested this on Windows and Linux. If it doesn't work on MacOS or any other OS, sorry. If it doesn't work for you on Windows or Linux: weird! Hit me up.\n- If you mess with the memory files in any way you'll mess up with your program memory, but seeing as this is topologically the same as messing with `/proc/mem` I consider this a cool feature.\n- I'm probably going to work on this *a little bit more* to add some quality-of-life features, but that's it. It's a shitpost, not a serious library.\n\n## (old) Demo\nhttps://github.com/shadyfennec/stupidalloc/assets/68575248/f2490dc1-8412-4450-9359-7387f79682ea\n","funding_links":[],"categories":["Rust"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshadyfennec%2Fstupidalloc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshadyfennec%2Fstupidalloc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshadyfennec%2Fstupidalloc/lists"}