Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upVectors are deserialized with spare capacity #241
Comments
|
You could make deserialized be a |
|
I see. In this case, I want to return the deserialized value and keep it alive permanently/until eviction. I can't think of a good way of achieving that without having ownership of the value. |
|
This functionality actually lives in the root serde crate, not in bincode. It looks like they purposefully only pre-allocate up to len 4096, and after that rely on the standard allocation behavior of the vec type, which explains the behavior you are seeing. https://github.com/serde-rs/serde/blob/97920be33aee4019bf7bd86bc3cf957a4de91413/serde/src/de/impls.rs#L862 I found this issue on the serde repo discussing this behavior, with a possible work around. |
|
Closing since this is behavior from serde itself. |
Thanks for a great library!
Serializing/deserializing a
Vec<u8>withlen > 4096will give aVecwith capacity equal to a power of two. This is undesirably for use cases where the deserialized data is not modified. Is there a way to deserialize aVecwithout allocating spare capacity?Reproduce with https://github.com/cswinter/bincode_overalloc: