I’m essentially trying to find the most performant way to get a simple read/write buffer.
Stack is hot so it’s probably better to put things there than to have static
array which is out of memory cache and whose address is out of TLB.
To answer your question, yes, this is undefined behaviour if the function is
called from multiple threads. It’s also undefined behaviour if, by accident, you take second reference to the array.
It’s unlikely that you really need to do anything fancy. I/O is usually orders
of magnitude slower than dealing with memory buffers. Unless you profile your
code and find the bottleneck, I’d advice against static mutable buffer.
Stack is hot so it’s probably better to put things there than to have static array which is out of memory cache and whose address is out of TLB.
To answer your question, yes, this is undefined behaviour if the function is called from multiple threads. It’s also undefined behaviour if, by accident, you take second reference to the array.
It’s unlikely that you really need to do anything fancy. I/O is usually orders of magnitude slower than dealing with memory buffers. Unless you profile your code and find the bottleneck, I’d advice against static mutable buffer.
PS. On related note, a shameless plug: Rust’s worst feature.