Are anonymous enums mostly available for performance reasons?

Mike Parker aldacron at gmail.com
Sat Apr 3 08:33:54 PDT 2010


bearophile wrote:
> Mike Parker:
> 
>> Also, and this is a big one for me, anonymous enums generate no TypeInfo, which can save a lot of space in the binary over named enums.<
> 
> This is interesting. How much size differences do you see?

I haven't actually had occasion to replace any named enums with 
anonymous ones in my own projects, but I recall this being an issue with 
Tango. But what I did in Derelict some time ago, was to replace hundreds 
of constant values with anonymous enums (another issue first highlighted 
by Tango) and got a tremendous savings in binary size, particularly in 
DerelictGL.

I just did a couple of minor tests to see how things stand now with both 
D1 and D2. In one file (1) I made around 430 const declarations. Another 
(2) replaced them all with a single, anonymous enum. In a third (3), I 
divided the anonymous enum into 25 named ones.

With both DMD 1.056 and DMD 2.042, (2) was the smallest and (1) the 
largest, but the difference is really negligible - around 1% with D1 and 
less than that with D2. While (3) is larger than (2), it's less than 
half a percent difference.

So either this doesn't hold true anymore or the scale isn't large 
enough. But it *was* an issue once upon a time. So I suppose that line 
can be stricken from the record.




More information about the Digitalmars-d mailing list