Is there a way to use std::io::Write
to write a stream directly to memory, without either pre-allocating the final at the outset, or potentially re-allocating the entire array while writing?
While Vec
implements Write
, this requires contiguous memory and I assume may re-allocate as with regular vector resizing.
Does Rust's stdlib
support something like this, or would it need to be implemented?
I want to write to memory which has the potential to go into multiple GiB. It's possible the memory is fragmented and it's possible that a contiguous region of the size I want isn't available. Instead, it's quite efficient to allocate many chunks (probably fixed power-of-2 size), and allocate more chunks as they're needed.
Once finished you could read the data back, compress the chunks in memory, cache some to disk, binary-diff with previous writes to de-duplicate chunks... etc.