digitalmars.D.learn - Struct vs. Class
- Chris (25/25) Jun 26 2015 I have still some classes lying around in my code. As threading
- Daniel =?UTF-8?B?S296w6Fr?= via Digitalmars-d-learn (3/36) Jun 26 2015 http://dlang.org/library/std/concurrency/init_once.html
- Daniel =?UTF-8?B?S296w6Fr?= via Digitalmars-d-learn (4/37) Jun 26 2015 bad link:
- Chris (3/42) Jun 26 2015 Thanks a million! This might do the trick and my classes can live
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.
Jun 26 2015
On Fri, 26 Jun 2015 11:11:15 +0000 Chris via Digitalmars-d-learn <digitalmars-d-learn 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
Jun 26 2015
On Fri, 26 Jun 2015 11:11:15 +0000 Chris via Digitalmars-d-learn <digitalmars-d-learn 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.bad link:
Jun 26 2015
On Friday, 26 June 2015 at 11:28:38 UTC, Daniel Kozák wrote:On Fri, 26 Jun 2015 11:11:15 +0000 Chris via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:Thanks a million! This might do the trick and my classes can live happily ever after :-)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.
Jun 26 2015