Is enum static?

Jonathan M Davis jmdavisProg at gmx.com
Thu Aug 8 15:38:18 PDT 2013


On Thursday, August 08, 2013 14:49:29 Ali Çehreli wrote:
> On 08/08/2013 02:45 PM, Borislav Kosharov wrote:
> > If I have any enum in a class is it one for all instances or one per
> > instance? Also are enums one per thread or only one?
> 
> More than that. :) enums are manifest constants.
> 
> Imagine that enum as being pasted into source code as is. This used to
> have surprising effects for AAs, as an enum AA would be instantiated
> from scratch everywhere that AA enum was used in the code. Perhaps it is
> still that way...

I'm sure that it's still that way. When you use an enum, you're effectively 
copy-pasting its definition, so you end up with a separate copy of it every 
time you use it. That's not a big deal for value types or string literals, but 
for arrays or AAs, it can result in a lot of allocations that you may not have 
wanted.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list