Reuse statically allocated strings (known length) with small changes in it


For performance critical task (sub 10 microseconds) - I need to send messages (strings) to socket - where only small part of it changes on every send, and number of symbols in message is the same and know in compile time

For that Im curious what are the best solutions avaiable in Rust, with the least possible latency

Currently what Im thinking of is ArrayString from arrayvec - Rust and just manipulating part of it via raw pointers (essentially like the library does when doing try_push internally)

Maybe there is easier ones and/or which are faster?


Since you are repeatedly reusing them, I don't think it hurts to heap allocate them. You can make a Box<[u8; LEN]> and modify the array as you please, then simply write bytes from the array.

Heap allocations are only more expensive than other types of memory when you create/destroy them.