Crates.io | packed_str |
lib.rs | packed_str |
version | 0.2.1 |
source | src |
created_at | 2023-07-10 04:03:12.456201 |
updated_at | 2023-07-10 05:52:48.046114 |
description | Store immutable strings in a single packed allocation |
homepage | |
repository | https://github.com/ericseppanen/packed_str |
max_upload_size | |
id | 912522 |
size | 12,031 |
Packed Immutable Strings
PackedStr
is a replacement for Vec<String>
when the strings are all
immutable.
The benefit of using PackedStr
is that all of the string data is stored
in a single heap allocation. This may save space compared to Vec<String>
,
where each String
has its own heap allocation, and associated costs (excess
String
capacity, allocator metadata, heap fragmentation).
In addition, each String
stores its own size and capacity, which are not
necessary due to the PackedStr
design.
PackedStr
is implemented as one large buffer containing all the string data,
and a list of indexes into the buffer. Each string slice can be reconstructed
from its index, and the index of the next string (or the end of the buffer,
for the last string).