Skip to content

Version 2 of Pack - #2

Open
mattcox wants to merge 2 commits into
mainfrom
v2
Open

Version 2 of Pack#2
mattcox wants to merge 2 commits into
mainfrom
v2

Conversation

@mattcox

@mattcox mattcox commented Aug 3, 2026

Copy link
Copy Markdown
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.

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