Thread overview
[Issue 21097] [REG2.083] Stack exhaustion upon large struct .destroy
July 30
https://issues.dlang.org/show_bug.cgi?id=21097

johanengelen@weka.io changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |industry

--
July 30
https://issues.dlang.org/show_bug.cgi?id=21097

--- Comment #1 from johanengelen@weka.io ---
Note: the 10MB symbol may lead one to believe that this is only a problem in rare cases. It isn't. At Weka, this bug is triggered with a dynamically allocated 300kb struct. Fibers do not have very large stacks.

--
July 31
https://issues.dlang.org/show_bug.cgi?id=21097

--- Comment #2 from johanengelen@weka.io ---
Two potential solutions:
```
// Avoid stack allocation, at the cost of virtual call to get the init symbol.
{
    auto arr = cast(ubyte[])typeid(T).initializer();
    if (arr.ptr is null) {
        (cast(ubyte*)val)[0 .. T.sizeof] = ubyte(0);
    } else {
        // Use fill to duplicate 'arr' to work around
https://issues.dlang.org/show_bug.cgi?id=16394
        (cast(ubyte*)val)[0 .. T.sizeof].fillbytes(arr);
    }
}

// Avoid stack allocation, at the cost of duplicating the init symbol (binary
size increase)
{
    import core.stdc.string : memcpy;
    shared static immutable T init = T.init;
    memcpy(&chunk, &init, T.sizeof);
}
```

(one cannot access the init symbol directly)

--