Object.factory() and exe file size bloat

Johannes Pfau via Digitalmars-d digitalmars-d at puremagic.com
Fri Aug 21 03:39:45 PDT 2015


Am Thu, 20 Aug 2015 22:21:30 -0700
schrieb "H. S. Teoh via Digitalmars-d" <digitalmars-d at puremagic.com>:

> On Fri, Aug 21, 2015 at 05:15:00AM +0000, deadalnix via Digitalmars-d
> wrote:
> > On Friday, 21 August 2015 at 05:06:47 UTC, Walter Bright wrote:
> > >This function:
> > >
> > >  http://dlang.org/phobos/object.html#.Object.factory
> > >
> > >enables a program to instantiate any class defined in the program.
> > >To make it work, though, every class in the program has to have a
> > >TypeInfo generated for it. This leads to bloat:
> > >
> > >  https://issues.dlang.org/show_bug.cgi?id=14758
> > >
> > >and sometimes the bloat can be overwhelming.
> > >
> > >The solution seems straightforward - only have Object.factory be
> > >able to instantiate classes marked as 'export'. This only makes
> > >sense anyway.
> > >
> > >What do you think?
> > 
> > Wait ? Why only classes marked export ? I don't follow the reasoning
> > here.
> 
> Because if your code imports the module that defines the class, you
> already know the class name (either by design, or by compile-time
> introspection) so you don't need to use the object factory.  It's only
> when you want to dynamically load new classes at runtime that you
> didn't know about at compile-time, that you need to use the object
> factory -- and that's also when you'd mark classes as 'export'.
> 
> Makes sense to me.
> 
> 
> T
> 

As Benjamin explained export works on library level, not on module
level. You export from a library (DLL/.so) not from a module, so the
analogy with D's 'import' is flawed.


More information about the Digitalmars-d mailing list