What are non-zero-sized values in Rust?

Viewed 128

I just read the documentation of the std::boxed module and encountered a sentence

For non-zero-sized values, a Box will use the Global allocator for its allocation

What are non-zero-sized values (in this context and in general)?

1 Answers

Non-zero-sized types are types that occupy one or more bytes in memory. This is typical of most types, since the point of most data structures is to, well, store data.

Zero-sized types are types that do not occupy any space in memory, like () and PhantomData. They have certain uses, but allocators need to handle them specially.

Related