-
Notifications
You must be signed in to change notification settings - Fork 9
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
Shrinking should never fail #42
Comments
Isn't that already how it works? The current version just returns a bool for if the shrinking happened or not. |
The current version returns a |
Ah, i was talking about the alloc-wg repo version: https://github.com/TimDiekmann/alloc-wg/blob/0fe6734bb2f1b6f537b244731c679ea34f3aceee/src/alloc/mod.rs#L240 |
|
@Lokathor This has just landed yesterday 🙂 |
Currently, if new_size > old_size {
if let Ok(size) = self.grow_in_place(ptr, layout, new_size) {
return Ok((ptr, size));
}
} else if new_size < old_size {
if let Ok(size) = self.shrink_in_place(ptr, layout, new_size) {
return Ok((ptr, size));
}
} else {
return Ok((ptr, new_size));
} could be changed to if new_size > old_size {
if let Ok(size) = self.grow_in_place(ptr, layout, new_size) {
return Ok((ptr, size));
}
} else if new_size < old_size {
let shrinked_size = self.shrink_in_place(ptr, layout, new_size);
if shrinked_size < old_size {
return Ok((ptr, shrinked_size));
}
} else {
return Ok((ptr, new_size));
} With #41, this would be the same. |
With #41, there is no The default implementation of both The default implementation of |
With I don't think simply returning |
It really depends on the allocator. If the allocator doesn't support freeing memory (e.g. The question is, what should the default behavior for
Option 1 would require that |
I think don't providing a default is the best option in the first place. This also allows us to add a default at a later point. The most intuitive default behavior would be 1. I guess as I don't expect |
This can't work. If |
@gereeter Makes sense. So we close this? |
I agree, let's just close this. |
I think it probably should. |
The
shrink_in_place
method (and theshrink
method proposed in #41) should be treated as "best effort" by the allocator and should never fail. If shrinking is not possible then they should simply return the original size to indicate that no shrinking has taken place.The text was updated successfully, but these errors were encountered: