Conversation
mattcox
commented
Aug 3, 2026
Owner
- If you're writing data whose layout the reader already knows (three doubles, for example) nothing extra is stored. But when a section is variable in size, you can now write it before knowing how big it is, and Pack fills in the size once it's done. In Pack 1 the only way was to build that section separately in memory and copy it in, which meant holding the largest one twice on every save.
- A reader can now tell where it is in the data. That makes it possible to skip a section you don't recognise, so a file written by a newer version still opens in an older one.
- If a recorded size doesn't match what's actually there, you get an error at that point. In Pack 1 it would read on into the next section and produce nonsense.
- Writing to a file and writing to memory produce exactly the same bytes, with no difference in how you call it.
- Byte order and text encoding are stated when you create the packer, and can't be changed elsewhere in the program. In Pack 1 both could vary by machine, or by any other code that happened to change a shared setting and silently change the file.
- Using Int no longer compiles. It's a different size on different devices, so a file written with it only reads back on a matching machine. Pack 1 only warned in documentation, and the problem never showed up on the machine you tested on.
- Large amounts of data are much faster. Arrays of numbers copy in one go rather than a byte at a time.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.