#array #memory #thin #box #pointers #length #empty

thinarray

A thin alternative to Box<[T]>

1 unstable release

0.1.0 Aug 24, 2024

#1653 in Algorithms

Zlib license

9KB
240 lines

ThinArray

This is a thin array type, meant to be an alternative to Box<[T]> when you have more arrays than actual data in them. It's only as big as one usize, and doesn't allocate for an empty array. It stores the array length with the data, whereas Box<[T]> stores it with the pointer. That helps with memory usage in many cases, with only the minor downside that accessing the length needs one more pointer indirection, unless it's 0. is_empty avoids that indirection.

Dependencies

~42KB