4 ms·
Given the "things move" point, would it be feasible to use a compacting memory manager with Rust, e.g. for memory-constrained applications?
by mwcampbell 9y ago
Given the "things move" point, would it be feasible to use a compacting memory manager with Rust, e.g. for memory-constrained applications?
- kibwen 9y agoRust allows you to take interior pointers to things (important for performance), which precludes the ability to move objects within memory at random. But for "memory-constrained" applications like embedded devices/microcontrollers, fragmentation isn't a problem in the first place because you often don't have a heap. For long-running programs that do have heaps, picking a modern memory allocator (jemalloc, tcmalloc, et al) will go a long way towards reducing fragmentation. And if you really need compaction, you could probably design a Rust library to provide it for certain types (though the operations it could provide would likely be restricted).
- smaddox 9y agoIf you're memory constrained, why would you use a GC? Just use manual memory arenas. They're trivially simple once you've seen how to use them. Unfortunately, Rust currently requires breaking some conventions and using unsafe quite a bit to do this without overflowing the stack, but it's just an extra keyword or two compared to C, and the safety guarantees outside of the unsafe code make up for it.