惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
Google DeepMind News
Google DeepMind News
J
Java Code Geeks
S
SegmentFault 最新的问题
Martin Fowler
Martin Fowler
罗磊的独立博客
T
The Blog of Author Tim Ferriss
N
Netflix TechBlog - Medium
大猫的无限游戏
大猫的无限游戏
Hugging Face - Blog
Hugging Face - Blog
Last Week in AI
Last Week in AI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
H
Heimdal Security Blog
N
News and Events Feed by Topic
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Privacy International News Feed
T
Tailwind CSS Blog
AWS News Blog
AWS News Blog
雷峰网
雷峰网
PCI Perspectives
PCI Perspectives
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
IT之家
IT之家
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
The Register - Security
The Register - Security
N
News | PayPal Newsroom
C
CERT Recently Published Vulnerability Notes
Microsoft Security Blog
Microsoft Security Blog
Attack and Defense Labs
Attack and Defense Labs
T
Tenable Blog
博客园 - 【当耐特】
Vercel News
Vercel News
GbyAI
GbyAI
博客园 - 司徒正美
量子位
T
Threat Research - Cisco Blogs
The Cloudflare Blog
The Last Watchdog
The Last Watchdog
MyScale Blog
MyScale Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Hacker News - Newest:
Hacker News - Newest: "LLM"
TaoSecurity Blog
TaoSecurity Blog
T
Troy Hunt's Blog
Y
Y Combinator Blog
P
Proofpoint News Feed
L
LINUX DO - 最新话题
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Jina AI
Jina AI
Recent Commits to openclaw:main
Recent Commits to openclaw:main
月光博客
月光博客
Apple Machine Learning Research
Apple Machine Learning Research

The Rust Programming Language Forum - Latest posts

What's everyone working on this week (21/2026)? Rust Function Call with one Param Iced + Canvas + Text: How do I create a style for canvas text "Value dropped while borrowed" as a lifetime mismatch Weird `use of moved value` behaviour Slightly surprising behavior of a while loop Clap: how to disable options after a certain positional argument How do i tell rust-analyzer what kind of bracket to use for a macro? Iterator + Borrow Checker: Work around borrowing already borrowed mutable variable Requesting data via mavlink SKILLS.md for Rust development 🧵 Stringlet UTF-8 Hack Option Niche? Iterator + Map - How do divide every element, including the last element, by the last element Why can't we store returned value of a function in a variable if one of the parameters goes out of scope My first crate :D, floop: A more convenient and less error prone replacement for loop `{ select! { .. }}` Sorting is slow because architectures are wrong — zan-sort redesigns the architecture, not the algorithm Iced Font - Create a custom monospace font to display dollar amounts Is the UnsafePinned RFC wrong about being able to return `&mut T` from `get_mut_unchecked`? Fixing Polars 0.37 compilation errors: Hashbrown 0.17 dependency conflict and decimal parsing Any plans for improving error diagnostic in Rust 2.0? How do I build completely offline? Is `&mut T -> &mut ManuallyDrop<T>` well-defined and sound? Would you use this? — fixtura, declarative fake data injection for tests Foreign trait restrictions on native types make generics hard to use Cargo Exclude Directive Compiler reasoning around a modulo counter Multiple mutable references to elements within one vector Handling non-`Send` data in a `Send` closure Rmquickjs - High-level MicroQuickJS bindings for Rust Iced + Rusqlite + Chrono: Problem with custom error type Why can&#39;t the Rust compiler infer the T type parameter in this BTreeMap::range call? Beginner building a Rust backend framework (AI-assisted) — feedback appreciated C++ to Rust -- Exceptions Re-exporting a trait with a custom derive_macro Gold linker is deprecated Why is using PhantomData valid in this case? Code review for Static Pool Allocator Discussion on Synchronous Crate Concurrency Refactor using Stackful Coroutines Model in Rust Can a future used only by `async fn` assume it won&#39;t be polled again after becoming ready? High-performance `fast-powi` crate Looking for a pool based allocator Why is this legal? What does it mean for Rustc to run "out of TLS keys"? Using async/await internally with no internal runtime, but exposing a nonblocking poll API — is this a reasonable design? Testing functions that use randomness `cargo-path`: improve coding agents&#39; ability to find Rust documentation Rust task runners Lifetime weird case Windows - USB device not detected A random rustc-ice-[...].txt file appeared Develop rust where the environment is setup in a docker Undefined Behavior: in-bounds pointer arithmetic failed: attempting to offset pointer by 20 bytes, but got alloc238 which is only 1 byte from the end of the allocation Unbug 0.5 - Runtime debug assertions Is there a tiny error in section 6.2 Reference types? Vasya go to (his) Home 🏡 Lifetime woes implementing ratatui::Widget for a reference Rusqlite + Chrono: How do I simplify code to obtain chrono datetime value From OOP to Rust – struggling with code organization and data structure design Way to avoid a self-referential struct Rust RF and audio resources/communities Whyhttp - HTTP mocks that fail where the bug actually is Using tokio channel permits in a tower service Arc::increment_strong_count design question (cross-post) `&T`, `&mut T`, `Pin<&mut T>` and `&Cell<T>`: Ways of Borrowing a `T` Ratatui detect arrow key press and release Feedback about post in medium Debugger not showing/offering variables? nestrs: a NestJS-style framework for Rust built on Axum and Tower Confusion about struct variance with &mut dyn How do I do hmr in rust How to call struct method as function pointer in loop Loops inside loops and mutable reference on Iterator VSCode - rust-analyzer - annoying re-builds due to RUSTC_BOOTSTRAP changed Borsh v1.6.1 example What's everyone working on this week (14/2026)? What's everyone working on this week (17/2026)? RawWakerVTable functions, did I write them correctly? Cargo test's verbose output - can I quiet it? Sem: semantic entity level version control CLI built with tree-sitter How do i get all the words in a string and convert it into a vector? Looking for feedback on my first tokenizer in Rust Frostmirror - (lightweight airgap alternative inspired from panamax and romt) - an offline cargo repository for airgap system that can be deployed through a docker image Does "ill-formed, no diagnostic required" exist in Rust? If a program is built with software floating-point emulation, is it affected by hardware floating-point environment? Rustc-link-lib static library How does crates.io and docs.rs store crates? Basic Object Oriented Programming in Rust Various input in one line error[E0080]: index out of bounds error when trying to install LuaCAD CSV to SQLite - Is it better to write records as they are being read Looking for feedback for a graph-based task scheduler This is my first project. I invented a new algorithm that even AI don't know. It's about bigint. And I'm 15. Thanks for watching. By the way, my crate named `nna` Why Windows rustc uses a different color scheme? Clap completion question Is RMW operation less prone to reading stale values than a pure load? Why are builds of my crate's test not consistent (cargo build vs cargo test vs VSCode-Test-Explorer) Type inference of generic parameters Cyw43 on STM32H723 Reducing code repetition with Vecs and fields Are there any object detection libraries out there for the Arduino?
Review: Static Multi Pool Allocator
@fuji-184 Fu · 2026-04-25 · via The Rust Programming Language Forum - Latest posts
Hello, I just finished my fixed size multi pool allocator. Now I need code review :> From the previous review, I got this following : small alignment can't be used to alloc bigger alignment the size must be power of the alignment size I created new project to address that with the following solution : there are multiple pool each pool can be configured to have different size and alignment the pool with size and alignment bigger than the data's size and alignment is chosen I already checked it with Miri and fixed the reported errors, is there still something wrong that I don't know? #![feature(allocator_api)] pub struct Block { next: Option<std::ptr::NonNull<Block>> } pub struct StaticMultiPoolAlloc<const N: usize> { start: [std::ptr::NonNull<u8>; N], head: [std::cell::UnsafeCell<Option<std::ptr::NonNull<Block>>>; N], block_size: [usize; N], aligns: [usize; N], layout: [std::alloc::Layout; N] } fn align_up(size: usize, align: usize) -> usize { (size + align - 1) & !(align - 1) } impl<const N: usize> StaticMultiPoolAlloc<N> { pub fn new(num_blocks: [usize; N], block_size: [usize; N], align_multiply: [usize; N]) -> Self { _ = align_multiply.map(|val| { if val == 0 { panic!("Align multiply must be > 0"); } }); let block_align = std::mem::align_of::<Block>(); let aligns: [usize; N] = align_multiply.map(|val| val * block_align); let base_block_size = std::mem::size_of::<Block>(); let block_size: [usize; N] = std::array::from_fn(|i| { let size = block_size[i].max(base_block_size); align_up(size, block_align) }); let layout: [std::alloc::Layout; N] = std::array::from_fn(|i| std::alloc::Layout::from_size_align( num_blocks[i] * block_size[i], aligns[i] ).expect("Error in creating layout in fn new -> PoolAllocator")); // SAFETY: the layout is valid, because if not it will trigger panic let starts: [std::ptr::NonNull<u8>; N] = std::array::from_fn(|i| { let start = unsafe { std::alloc::alloc(layout[i]) }; let start_ptr = std::ptr::NonNull::new(start).expect("Error OOM in fn new -> PoolAllocator"); unsafe { for j in 0..num_blocks[i] { let current_ptr = start.add(j * block_size[i]).cast::<Block>(); let next_ptr = if j < num_blocks[i] - 1 { Some(std::ptr::NonNull::new_unchecked(start.add((j + 1) * block_size[i]).cast::<Block>())) } else { None }; (*current_ptr).next = next_ptr; } } start_ptr }); let head: [std::cell::UnsafeCell<Option<std::ptr::NonNull<Block>>>; N] = std::array::from_fn(|i| { std::cell::UnsafeCell::new(Some(std::ptr::NonNull::new(starts[i].as_ptr().cast::<Block>()).unwrap())) }); Self { start: starts, head, block_size, aligns, layout, } } } impl<const N: usize> Drop for StaticMultiPoolAlloc<N> { fn drop(&mut self) { // SAFETY: deallocate using the pointer. The layout is saved, so it is the correct layout for (i, val) in self.start.iter().enumerate() { unsafe { std::alloc::dealloc(val.as_ptr(), self.layout[i]); } } } } unsafe impl<const N: usize> std::alloc::Allocator for StaticMultiPoolAlloc<N> { #[inline(always)] fn allocate(&self, layout: std::alloc::Layout) -> Result<std::ptr::NonNull<[u8]>, std::alloc::AllocError> { let size = layout.size(); let align = layout.align(); //let base_align = std::mem::align_of::<Block>(); let index = self.aligns.iter().enumerate().position(|(i, &val)| { size <= self.block_size[i] && align <= val }); let i = index.ok_or(std::alloc::AllocError)?; let head_ptr = unsafe { &mut *self.head[i].get() }; if let Some(block) = *head_ptr { let taken_block = block; unsafe { *head_ptr = block.as_ref().next }; let ptr = taken_block.cast::<u8>(); return Ok(std::ptr::NonNull::slice_from_raw_parts( ptr, self.block_size[i] )); } Err(std::alloc::AllocError) } #[inline(always)] unsafe fn deallocate(&self, ptr: std::ptr::NonNull<u8>, layout: std::alloc::Layout) { let new_block = ptr.cast::<Block>(); let align = layout.align(); let index = self.aligns.iter().enumerate().position(|(_, &val)| { align <= val }); let i = index.ok_or(std::alloc::AllocError).unwrap(); // dereference raw pointer is unsafe let head_ptr = unsafe { &mut *self.head[i].get() }; unsafe { (*new_block.as_ptr()).next = *head_ptr }; *head_ptr = Some(new_block); } } #[derive(Debug)] #[repr(align(64))] struct Tes(i32); fn main() { /* [pool 1, num block: 4, each block: 80 byte, total byte: 80*4, align: 8*1] [pool 2, num block: 2, each block: 1024 byte, total byte: 1024*2, align: 8*8] total prealloc in entire pool: (80*4) + (1024*2) fixed size, panic if no enough size available single threaded usage, each thread has their own pool so there is no locking, maximizing cpu cache hit */ let pool: StaticMultiPoolAlloc<2> = StaticMultiPoolAlloc::new([4, 2], [80, 1024], [1, 8]); let mut vec = Vec::with_capacity_in(2, &pool); vec.push(Tes(10)); println!("{:?}", vec[0].0); }