-
Notifications
You must be signed in to change notification settings - Fork 296
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
Deque
lacks capacity
#308
Comments
Yes, I very intentionally omitted All code I've seen that tries to make decisions about shrinking storage based on The example code in the discussion you linked to was especially alarming to me:
16 seemed like a rather low value -- depending on the Element type and the whims of the system allocator, malloc may sometimes give us 16 items' worth of bytes even if we only ask for just a couple of them. Given this, I'd prefer to figure out a more direct way to detect and recover from temporary allocation spikes. I generally dislike the idea of having the core resizing logic live in client code -- it ought to be part of the container implementation, as it needs to evolve with it. Making Deque automatically shrink itself is one way to achieve this; another (possibly less disruptive) idea would be to expose an explicit operation to shrink the container to be near a certain target size. To do this, I think I'm very much open to adding direct support for shrinking. (PRs are welcome, if you have time to experiment!) I'd need a bit more convincing to understand why exposing a public |
Oh I see, that makes sense. Thanks for shedding some light on why
Yeah, that seems absolutely fair, I'm more interested in having a way to shrink the storage. The lack of I'll try to find some time to experiment with the less disruptive explicit shrink operation. |
Deque
is often used as a buffer. However, you can't always control how much data you accept. In these cases it usually makes sense to reclaim storage space if the capacity grows beyond some limit to avoid holding on to too much memory unnecessarily.This isn't possible with
Deque
because its capacity is as an implementation detail.In this thread @lorentey suggested letting
Deque
shrink on removal along and addinginit(minimumCapacity:persistent:)
. I think this would be sufficient although as described it has a minor drawback that it wouldn't lazily grow up to a capacity limit.capacity
is a non-starter based on Deque.md?Deque
to shrink automatically on removal?The text was updated successfully, but these errors were encountered: