redjack/libcork — pull request #53 by dcreager (2013-04-25 01:12:58+00:00)
Title: Revamped resizable arrays

This patch makes some major changes to the resizable array implementation. The new implementation is API-compatible with previous versions, but not ABI-compatible. All code that uses resizable arrays will need to be recompiled.

We no longer reserve space in the array itself for a small number of elements; the element storage is now always allocated from the heap. The `cork_array` type now contains a `priv` pointer, which lets us maintain API compatibility with previous versions — in which you allocate a `cork_array` instance yourself, while still being able to maintain ABI compatibility moving forward. (This ensures that the public `cork_array` type is of fixed size, even if we add new features; any extra fields needed for those new features will be placed into the opaque struct that the `priv` field points to.)

More interestingly, you can now provide a handful of callback functions, which let you automatically initialize and finalize array entries as they're used and discarded. You can provide separate initialization callbacks for when an entry is used for the first time, or reused. Similarly, you can provide separate finalization callbacks for when an element is removed without freeing its underlying storage, and for when the array element is freed.