enum question

Eric eric at makechip.com
Tue Mar 18 14:18:24 PDT 2014


On Tuesday, 18 March 2014 at 20:56:45 UTC, Adam D. Ruppe wrote:
> On Tuesday, 18 March 2014 at 20:40:36 UTC, Eric wrote:
>> However, using struct type seems inefficient because structs 
>> are pass by value.
>
> That's not necessarily a problem, especially if the struct is 
> small, passing by value is faster than by reference.
>
> What is your code trying to do?
>
>> Can enums be made of classes yet, or is there a way to make 
>> the enum based on structs more efficient?
>
> enums can't be classes, but you could make a static class 
> constructed at compile time and pass that reference around.

Hmmm... What do you think the crossover point is for performance
of value vs reference? ie, how large can a struct be before
passing it around gets slower than passing around a reference?
(I would guess 8 bytes, but that's just a guess).

I am trying to emulate the java enum type. Enums are great for 
data
safety in API design.  The more immutable data they contain the
better in my opinion - hence my concern about performance.

-Eric


More information about the Digitalmars-d-learn mailing list