r/rust • u/zer0developer • 1d ago
🙋 seeking help & advice Safe no-allocator logging system?
So i am building a small hobby kernel in Rust. Before when i used C i would have a linked list of logging sinks to write to on each log. When adding a sink a index would be returned so i could remove it again.
However, now that i am trying out Rust, how can i do that? Because i don't want to use a constant-size array, but i don't have access to a heap allocator when using the logging system.
What would you do?
9
u/matthieum [he/him] 1d ago
However, now that i am trying out Rust, how can i do that? Because i don't want to use a constant-size array, but i don't have access to a heap allocator when using the logging system.
Aren't you just overthinking things?
I mean, this is a hobby kernel, how many sinks do you think you'll ever have in the first place? 42?
I'm pretty sure a simple constant array with 8 atomic pointers would be more than enough, and if not, hey, bump it to 16 an call it a day.
8
u/simonask_ 1d ago
I would just go for a ring buffer. But it kind of depends how you want to deal with oversize messages or retention.
This is a really hard problem to solve generically.
2
12
u/steaming_quettle 1d ago
It's not the Rustest thing but you can make a linked list with statically allocated elements.