Bug 19987 – std.variantN wastes space

Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-06-19T14:19:51Z
Last change time
2019-06-21T13:26:41Z
Keywords
pull
Assigned to
No Owner
Creator
John Colvin

Comments

Comment #0 by john.loughran.colvin — 2019-06-19T14:19:51Z
Because the function pointer is stored before the union and for anything other than small sizes the union is larger (and has larger alignment), if you ask for a size of 24 you get 48 as the total size, as opposed to 32 if the fptr and union order is swapped.
Comment #1 by dlang-bot — 2019-06-21T06:11:14Z
@Kriyszig created dlang/phobos pull request #7082 "19987 - Reduce memory used by VariantN" fixing this issue: - Fix Issue 19987 - Reducing memory used by VariantN Swapping the fptr and union around will avoid unnecessary padding. https://github.com/dlang/phobos/pull/7082
Comment #2 by dlang-bot — 2019-06-21T13:26:41Z
dlang/phobos pull request #7082 "19987 - Reduce memory used by VariantN" was merged into master: - 6da85c4f8cd8a123817fe908f709e879766a1435 by Kriyszig: Fix Issue 19987 - Reducing memory used by VariantN Swapping the fptr and union around will avoid unnecessary padding. https://github.com/dlang/phobos/pull/7082