-
Notifications
You must be signed in to change notification settings - Fork 294
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 fixed-size Deque
#309
Comments
My initial instinct is that this feature would not be a good fit with the The headlining feature of Swift’s collection types is that they implement value semantics with the copy-on-write optimization. This means that any operation that mutates a collection can (and does) implicitly and automatically reallocate storage. Automatic resizing goes hand in hand with that — I think disabling resizing but not copy-on-write would be weirdly inconsistent.
var a = Deque(minimumCapacity: 100)
let b = a
a.append(42) // This will allocate a second buffer to avoid changing `b`. Neither this behavior, nor the dynamic resizing prevent the use of
The first requirement avoids the initial ramp-up of exponentially growing allocations until we reach the stable working size. Questions:
Fixed size Rather, I expect we'll soon implement noncopyable variants of |
If pressed, it would be possible to expose a fixed-capacity deque variant as a new class type, possibly even rewriting the existing |
Currently,
Deque
can be initialized with aminimumCapacity
andDeque
's internal storage will grow capacity as the number of elements in theDeque
increases. It is not possible today to limit the maximum capacity ofDeque
.This limitation prevents the usage of
Deque
as a traditional ring buffer/circular buffer which is backed by fixed-size, contiguous memory. Ideally,Deque
would allow a user to provide acapacity
oreagerCapacity
which results in theDeque
's storage eagerly allocating contiguous memory for its elements and enforcing the capacity restriction. This is a relatively common use case for high-performance systems which utilize fixed-size queues.The text was updated successfully, but these errors were encountered: