Skip to content

feat: add reset:"maxcap=N" to let oversized slice arrays go - #14

Merged
darxnet merged 1 commit into
mainfrom
feat/maxcap
Nov 16, 2026
Merged

darxnet merged 1 commit into
mainfrom
feat/maxcap

Conversation

@darxnet

@darxnet darxnet commented Nov 16, 2026

Copy link
Copy Markdown
Owner

A slice tagged reset:"maxcap=N" keeps its backing array, cleared, while cap is at most N, and is set to nil above it (the array is let go, not cleared), so one huge use does not pin its memory for every later one. Works in both modes.

  • N is a constant integer expression evaluated in the package: 4096, 64<<10, a package constant; it is emitted as written.
  • Refused on anything but a plain slice without call=, value=, release= or its own Reset, and for a limit that is negative, not an integer, not a constant or overflows int64.
  • Cost model: +1 over a plain slice in both modes.
  • README: the tag, its cost row, the updated rule on slice capacity, and a paragraph in "Why goreset?" on resetting everything by default; doc.go example.

Tests: TestMaxCap (both modes, under and over the limit, built and run with go vet/go test), TestMaxCapErrors.

A slice tagged maxcap=N keeps its backing array, cleared, while cap is at
most N, and is set to nil above it, so one huge use does not pin its memory
for every later one. N is a constant integer expression evaluated in the
package (4096, 64<<10, a package constant); the tag is refused on anything
but a plain slice without call=, value=, release= or its own Reset.

README: the tag, its cost in the model, the updated rule on slice capacity,
and why resetting everything by default beats a hand-written list.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@darxnet
darxnet merged commit ccac6e7 into main Nov 16, 2026
9 checks passed
@darxnet
darxnet deleted the feat/maxcap branch November 16, 2026 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant