fn alloc_mut<T>(t: T) -> &'static mut T
Expand description
Allocates a mutable reference to a value on a thread-local storage arena.
This function takes an input of any type T
, allocates it on a thread-local arena, and returns a mutable reference with a static lifetime.
It uses a thread-local storage mechanism provided by THR_ARENA
to ensure that the allocated object resides in memory local to the thread, improving performance for concurrent processes.
The allocation is done by casting the allocated value to a mutable raw pointer, and then converting it to a mutable reference with a static lifetime using unsafe operations.
The use of unsafe
indicates that it is the programmer’s responsibility to uphold the memory safety guarantees manually.
This approach is typically employed when fine-grained control over memory allocation and lifetimes is necessary for performance-critical code.