3 ms·
> In Rust, from what I've seen, you basically have the option to avoid heap allocations almost entirely which is fantastic for performance. Not really. Any tim
by burntsushi 12y ago
> In Rust, from what I've seen, you basically have the option to avoid heap allocations almost entirely which is fantastic for performance.
Not really. Any time you using a `Vec<T>` or a `String` type, you'll be heap allocating.
I suspect what you meant to say is that Rust does not force programmers to use some sort of garbage collection (whether it be reference counting or otherwise). That is indeed the case. I've written a fair amount of Rust code and haven't needed to use a GC at all.
- pcwalton 12y ago> Not really. Any time you using a `Vec<T>` or a `String` type, you'll be heap allocating. Well, we have the SmallVec type to avoid this if you can bound the size of your vectors. I would also like to introduce scratchpad allocators at some point, which should allow you to avoid heap allocations even for those. Either way, there are many ways you can avoid heap allocations entirely. For example, my NES emulator does not call malloc() during gameplay, at all.
- burntsushi 12y agoOh cool, I didn't know about `SmallVector`! That's clever. > Either way, there are many ways you can avoid heap allocations entirely. For example, my NES emulator does not call malloc() during gameplay, at all. Definitely. Executing searches from `regex!` expressions won't heap allocate either. :-) (Sans the return value, but maybe that can be avoided too.)