How expensive is boxing a ZST

I understand from the docs that there are still restrictions to the box pointer even if the pointee is a ZST value (the Box doc mentions validity and alignment), which makes sense.

But how expensive is it for the pointee side? Is anything actually heap-allocated?
It's easy to assume not, but I'd like to know just how expensive boxing a ZST value really is.

Nothing gets allocated if you box a zst


The Box itself still occupies normal pointer size though.


@cuviper I expected as much. So ultimately the price paid for boxing a ZST value is the size of a pointer. That's acceptable in this case.

Thanks guys!

A quick code demonstration:

It just gives a constant pointer.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.