Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support decoding into preallocated memory #33

Open
Ralith opened this issue Jul 30, 2018 · 3 comments
Open

Support decoding into preallocated memory #33

Ralith opened this issue Jul 30, 2018 · 3 comments

Comments

@Ralith
Copy link

Ralith commented Jul 30, 2018

This is useful for skipping a potentially large copy when e.g. uploading texture data to a GPU, by decoding directly into a driver-allocated staging buffer or mapped memory. It would make sense for higher-level, more magical owned-memory decoders to be defined in terms of such a primitive. Compare the png crate's next_frame method.

@Ralith
Copy link
Author

Ralith commented Jul 30, 2018

It would also be nice to support encoding into preallocated memory, or even arbitrary io::Write impls.

@kornelski
Copy link
Owner

I've looked at io::Write before, but it won't work with the current implementation which writes things out of order (e.g. needs to re-read its own data to set checksums). Also the library can reserve memory it needs, but io::Write to a Vec would need to keep resizing the buffer.

However, decoding to a pre-allocated buffer makes sense and should be easy to imeplement.

@Ralith
Copy link
Author

Ralith commented Jul 30, 2018

it won't work with the current implementation which writes things out of order (e.g. needs to re-read its own data to set checksums).

If computing these checksums on the fly is too onerous, io::Write + io::Seek could be used. An in-memory convenience function could still query the total required storage and reserve space in a Vec (or on the filesystem, or ...).

Decoding's the case I'm actually affected by, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants