How to get to a class initializer through introspection?
nospam at example.com
Tue Aug 4 10:13:53 UTC 2020
Am Tue, 04 Aug 2020 09:31:16 +0000 schrieb Johan:
> On Tuesday, 4 August 2020 at 02:03:34 UTC, Andrei Alexandrescu wrote:
>> On 8/3/20 10:44 AM, Johan wrote:
>>> On Monday, 3 August 2020 at 13:01:55 UTC, Andrei Alexandrescu wrote:
>>>> Would it be effective to iterate through the .tupleof and initialize
>>>> each in turn?
>>> Possibly. IIRC, the spec obliges us to initialize the padding
>>> in-between address-aligned members aswell, such that a memcmp works to
>>> compare structs. If that is true, then we have to initialize the
>>> padding aswell and a memcpy would be that much nicer.
>> To play devil's advocate, the padding bytes should not have been
>> changed by user code in the first place :o).
> But the memory into which objects are placed will be tainted and thus
> the padding areas will not be the same for each object. (it's the same
> for =void members. All can be incorporated into the initializer
> function, but it's work.)
I wonder whether an initial memset + then initializing members may be a
good solution? The compiler backends may be clever enough to optimize the
memset (e.g. if there are no gaps, so it's completely redundant, if there
is a single gap and explicitly filling that gap is more efficient than
zeroing everything, ...).
However, in some cases a memcpy which copies both member initialization
data and padding may be better? I'm not sure how to decide when which
option is better or whether we can somehow have both...
More information about the Digitalmars-d