Struct vs. Class

Daniel Kozák via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jun 26 04:27:21 PDT 2015


On Fri, 26 Jun 2015 11:11:15 +0000
Chris via Digitalmars-d-learn <digitalmars-d-learn at puremagic.com> wrote:

> I have still some classes lying around in my code. As threading 
> is becoming more and more of an issue, classes and OOP in general 
> turn out to be a nuisance. It's not so hard to turn the classes 
> into structs, a lot of classes are in fact singletons (yes, I've 
> been kinda fading out classes for a while now). My question is 
> now, what do I have to keep in mind if I turn a cached class into 
> a cached struct, i.e.
> 
> initProgram()
> {
>    auto myClass = new AwesomeDoEverything.instance();  // lives 
> for the rest of the program, is a singleton
> }
> 
> // ...
> 
>    myClass.call(input);
> 
> initProgram()
> {
>    auto myStruct = AwesomeDoEverything();  // lives for the rest 
> of the program
> }
> 
> // ...
> 
>    myStruct.call(input);  // Can live in different threads without 
> reinitializing it.
> 
> Or is there a way I can make a singleton class "thread-able"?
> 
> I cannot afford to re-initialize certain classes / structs 
> because I don't wanna hit the file system every time I do so.

http://dlang.org/library/std/concurrency/init_once.html


More information about the Digitalmars-d-learn mailing list