-
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
Separate methods v.s. "mode" parameters #58
Comments
After playing around with |
While I might be convinced to split |
We could add |
Eh, I guess I don't feel too strongly either way. |
I think the Am I overlooking an important use case? |
If we decide to use |
Growing and shrinking in-place does not touch the data stored in the memory block (except the tail when shrinking ofc). The pointer returned from a previous call to |
What's a specific use case of The fact that all three of the existing implementations just return error on |
After thinking about it for a bit, I agree with @nnethercote: in-place reallocation is a rather niche operation which can be exposed with an extension trait on crates.io if it really becomes necessary. Another strong point in favor of removing in-place reallocation is that none of the standard allocators even support this functionality. |
This is a good point. Then we should just remove the API, use the second approach, replace |
I agree. Shall we go ahead with this and unblock rust-lang/rust#72417? |
Removing in-place reallocation from
|
Yeah, I still think |
Not directly:
With |
To replace These methods can be on |
Irrespective of whether we move ahead with the separate decisions, I'd be in favour of not lumping the changes together. Let's just make those two decisions separately and if both are accepted make two PRs. That also makes the "history" cleaner, if both do get accepted. In general, I am in favor of removing the in-place reallocation and reverting back to separate methods. |
I will come back to this next week and create a PR upstream, which removes |
No need to block on me, but if the auto-assigned reviewer is unresponsive feel free to ping me. |
…Amanieu Remove in-place allocation and revert to separate methods for zeroed allocations closes rust-lang/wg-allocators#58
Removing in_place broke the solution of #40. I have a similar situation: a buffer that can have beginning erased and it'd be great to not copy erased part. However this is theoretical I'm not sure about the real impact. @nnethercote you seem to be experienced, did you ever come across something like this and found out that it doesn't help performance? |
Also just realized that a simple |
@Kixunil I don't recall any situations like that. |
#41 has split
realloc
into separategrow
andshrink
methods. However as of this writing some methods takeAllocInit
orReallocPlacement
parameters that are effectively boolean mode switches.Part of the reasoning for separate methods is that most callers are always in one of the two cases, so separating saves a branch in the allocator implementation. The same seems to apply to
AllocInit
andReallocPlacement
.The current design with 5 methods seems inconsistent to me. I think the trait should pick one principle among easier/nicer-looking API or single-purpose methods. This would give either 4 methods:
alloc
dealloc
realloc
by_ref
Or 10 methods:
alloc
alloc_zeroed
dealloc
grow
grow_zeroed
grow_in_place
grow_in_place_zeroed
shrink
shrink_in_place
by_ref
I tend to favor the latter. The reason against it given in #44 is that this "blows up the trait". But I feel 10 methods is not that bad, especially given that they are not 10 completely different behaviors that need to be learned independently, but follow a pattern that’s reflected in their names.
The text was updated successfully, but these errors were encountered: