3 ms·
Interesting that a language that targets embedded (amongst other things) has a default vector allocator for space for 4 entries of objects between 2 and 1024 by
by Robin_Message 4y ago
Interesting that a language that targets embedded (amongst other things) has a default vector allocator for space for 4 entries of objects between 2 and 1024 bytes. I can imagine that being wasteful for code that has a lot of very short lists of non-trivial objects (e.g. something like configuration options).
Although I expect it is overridable in some way but I don't know enough Rust to know how.
- gameswithgo 4y agoYou can specify the capacity on creation: Vec::with_capacity(foo) There are also alternative vector like types for different use cases, and you can roll your own.
- __s 4y agoThere's also crates to avoid heap allocations for usually small vectors: tinyvec, smallvec, arrayvec Note: gameswithgo you seem to be shadow banned. Your comment history looks alright tho. You may want to email hn@ycombinator.com asking to have that fixed (edit: found the culprit https://news.ycombinator.com/item?id=30732886 https://news.ycombinator.com/item?id=30732886)
- nynx 4y agoVec and allocators aren’t usually used for embedded rust since the std library can be disabled. (Though the _core_ library is still accessible)