[Issue 1845] New: Variant and VariantN cannot handle structs of arbitrary size

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Feb 16 13:38:08 PST 2008


http://d.puremagic.com/issues/show_bug.cgi?id=1845

           Summary: Variant and VariantN cannot handle structs of arbitrary
                    size
           Product: D
           Version: 2.010
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: dhasenan at gmail.com


Variant can only handle structs and static arrays of at most 2 * sizeof(size_t)
bytes. VariantN can handle structs and static arrays of any specified size.

This is intended behavior. However, it wastes memory: if I know I might need to
store a struct of 64 bytes, then I'll store a char with 63 bytes of padding. If
I am writing a library, I cannot use Variant or VariantN because I do not know
what size structs the end user might want to use.

I could store an array of VariantN and, if I need to store something larger
than the current maximum size, copy everything into another array of VariantN
with a larger maximum size. I'd have to store this array in a Variant, as well,
since its type will continue to change. But that's just silly. Variant is
supposed to be a solution for boxing, so I shouldn't have to concern myself
with size. At least, I should be able to avoid those concerns, even if they are
exposed.

For comparison, Tango stores large structs on the heap, and can store
arbitrarily large structs.


-- 



More information about the Digitalmars-d-bugs mailing list