getty-zig / getty

A (de)serialization framework for Zig
https://getty.so
MIT License
200 stars 13 forks source link

Document allocation model #129

Closed ibokuri closed 1 year ago

ibokuri commented 1 year ago

From https://github.com/getty-zig/getty/issues/127#issuecomment-1666273887,

[...] Getty's allocation story during deserialization:

  • Deserialized pointer values returned by an access method (e.g., nextKey) will be freed upon failure and, where applicable1, upon success, if the value's corresponding isXAllocated method (e.g., isKeyAllocated) returns true.
  • Deserialized pointer values not returned by an access method will always be freed upon failure and, where applicable1, upon success.


  1. Generally speaking, "where applicable" means whenever a deserialized value is not part of the final value returned to the end user. For instance, if a heap-allocated string is visited to produce an integer, the string isn't part of the final, returned integer and so we'd free it even upon success.

note to self: one place that references the allocation model is the doc comment for free.