A segment array is a data structure that stores items in multiple contiguous segments, where each segment doubles in size. Unlike dynamic arrays, it provides stable pointers (items never move), works well with arena allocators, and maintains constant-time random access. The implementation uses a fixed-size array of segment pointers and bit operations for efficient index calculations. While not fully contiguous like traditional arrays, it offers a good balance of growability, memory efficiency (~75% average), and pointer stability, making it ideal for scenarios with unknown item counts and arena allocation patterns.

6m read timeFrom danielchasehooper.com
Post cover image
Table of contents
The ImplementationIn UseComparisonConclusion
1 Comment

Sort: