Crate hcstatic_str

source ·
Expand description

Global, permanent, packed, hashconsed, short string storage.

  • supports strings up to 256 bytes
  • derefs to a &str, but uses only 1 word on the stack and len + 1 bytes on the heap
  • the actual bytes are stored packed into 1 MiB allocations to avoid the overhead of lots of small mallocs
  • Copy!
  • hashconsed, the same &str will always produce a pointer to the same memory

CAN NEVER BE DEALLOCATED

Structs

  • This is a pointer into static memory that holds the actual str slice. This type is 1 word on the stack, the length is stored in the heap as a byte. Deref is quite cheap, there is no locking to deref. Only try_from can be expensive since it performs the hashconsing.