Package dev.relism.flash.bytes
Class SlicePool
java.lang.Object
dev.relism.flash.bytes.SlicePool
A small, fixed-size ring of
PooledSlice instances — one per ConnectionScratch-
Http1HeaderMap.view, QueryParams.view, PathParams.view).
Why a ring, not a single reused slice
A single reused slice (the shapeHttp1HeaderMap.forEach already uses for its two
nameSlice/valueSlice fields) is correct only when the caller is guaranteed to
finish with one slice before the next is produced — true for a single forEach callback
invocation, false for view(): a handler might reasonably call
headers.view("A") and headers.view("B") and want to compare both. A ring of
size slices lets up to size calls' results stay simultaneously valid.
Lifetime contract
A slice returned byacquire(byte[], int, int) is valid until either the request ends, or acquire(byte[], int, int)
is called size more times on the same pool (at which point the ring has wrapped around
and repositioned that same slot for a new caller) — whichever comes first. This must be
restated precisely on every method that hands out a slice from a pool (see
Http1HeaderMap.view's Javadoc for the canonical wording); it is a real, testable hazard, not
a hypothetical one — see SlicePoolTest#wraparoundAliasesThePreviouslyReturnedSlice for
a demonstration.-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
SlicePool
public SlicePool(int size) A ring ofsizereusable slices.sizemust be at least 1.
-
-
Method Details
-
size
public int size()How many slices this pool cycles through before a caller's slice is reused. -
acquire
Returns the next slice in the ring, repositioned overarray[offset, offset + length). Zero allocation — the returned instance already existed.
-