-
Notifications
You must be signed in to change notification settings - Fork 94
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
Rasterband::write
with Buffer<T>
forces unnecessary data copy.
#453
Comments
For anyone running into this, you can use the following idiom as a workaround: fn write_data_with_gdal(data: Vec<u8>) -> Vec<u8> { // pass by value and return back
let driver = DriverManager::get_driver_by_name("GTiff").unwrap();
let ds = driver.create(...).unwrap();
let mut rb = ds.rasterband(1).unwrap();
let dims = (data.len(), 1);
let buf = Buffer { size: dims, data: data }; // no clone()
rb.write((0, 0), dims, &buf).unwrap();
let Buffer { data, .. } = buf;
data
} |
@lnicola What if you have a |
No, we'd need two buffer variants or a view over owned or borrowed data. |
Would you be opposed to a |
We'd need another one for the block function(s) though. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When working with large rasters, minimizing the number of data copies is important. The
Rasterband::write
method as it currently stands, forces some users into an additional buffer copy.To illustrate, consider the following use case (pseudo-ish code):
Seems reasonable, no? And let's assume for external reasons we only have control over the implementation of
write_data_with_gdal
. Problem arises when we try to implement it:The
Rasterband::write
method looks like this:It wants the data as as a reference to a
Buffer<T>
, which looks like this:The contained
Vec
is owned byBuffer::data
. We only have a&Vec<u8>
. So to callwrite
, even thoughwrite
only needs aBuffer<T>
reference, the only way to create the referent is to clone our&Vec<u8>
parameter:I'd argue we need an alternative to this
write
method for users not wishing to incur the additional memory and time overhead. One might argue that the user should only work withBuffer<T>
instances, but given that working interoperability with otherVec<T>
-based APIs is very common in the raster space, we should support writing aVec<T>
without theclone()
cost.The text was updated successfully, but these errors were encountered: