6 comments

[ 0.17 ms ] story [ 57.6 ms ] thread
Off hand question for Rust: if memory is borrowed, I gather Rust does not need --- perhaps resists --- C++ style allocators? Here I give emphasis to owner of the (heap) data rather than efficiency. Both languages might use an allocator for fast re-use, less fragmentation, MT support etc.. On the the hand STL strings and containers are replete with allocators in their constructors leading to such questions like if two non-empty std::vector<T> A,B vectors are equal (same size, specialized both on T, resp. elements equal) is A==B true if A has a different allocator from B?
Borrowing is just a pointer, no allocation at all. It can point at anything, heap or stack.
Right. My question was off base there. Should have focused on memory ownership insofar as where the memory goes when deallocated.
The usual case is the same as C; commonly a call to free, but if you’ve written your own allocator or something, you get to decide. The language doesn’t know anything about heap allocation, it’s a library thing.
In the corner of rust I have experience in (web servers, ffi for cli's) you just use the system allocator. I know it's not that hard to switch that default allocator to something like jemalloc, but I've never needed to do that. Rust is currently refactoring the standard library to be genetic over the allocator like c++ so you you can have two vectors with different allocators, but I don't really understand the point outside of stuff like kernel development.
There are a lot of low level algorithms that benefit from custom allocators which allow them to take advantage of SIMD instructions.

Haven't used rust in a long time, but back in school I called out to the c++ fftw library from rust, which wants its own allocator to be used for this purpose.

That said, at least at that point in time (or due to my naivety) it was rather straightforward to hook up: https://github.com/PaulFurtado/rusty_bars/blob/master/src/ff...

That code looks like it just handled arrays, but I recall having implemented Vec at some point but I guess I probably removed it from the final code