Why are multiple instances of the single enum created?
    Jacob Carlborg 
    doob at me.com
       
    Mon Feb  1 09:52:07 UTC 2021
    
    
  
On Monday, 1 February 2021 at 09:40:20 UTC, Per Nordlöw wrote:
> An enum only exists at compile-time, and does not occupy any
> space. Each time it's referenced, a new instance of the value
> is created. Why is that? Seems like a waste of resources to the 
> compiler.
It makes perfect sense for numeric values, strings, characters 
and similar values. Why waste extra space on a variable if it's 
not needed?
If you don't want a new instance, then don't use `enum`. Use 
`immutable` instead.
--
/Jacob Carlborg
    
    
More information about the Digitalmars-d-learn
mailing list