Program size, linking matter, and static this()

Sean Kelly sean at invisibleduck.org
Fri Dec 16 14:49:23 PST 2011


On Dec 16, 2011, at 10:29 AM, Andrei Alexandrescu wrote:
> 
> But in experiments it seemed like program size would increase in sudden amounts when certain modules were included. After much investigation we figured that the following fateful causal sequence happened:
> 
> 1. Some modules define static constructors with "static this()" or "static shared this()", and/or static destructors.
> 
> 2. These constructors/destructors are linked in automatically whenever a module is included.
> 
> 3. Importing a module with a static constructor (or destructor) will generate its ModuleInfo structure, which contains static information about all module members. In particular, it keeps virtual table pointers for all classes defined inside the module.

What is gained from having class vtbls referenced by ModuleInfo?  Could we put them elsewhere?


More information about the Digitalmars-d mailing list