How to share an appender!string?
Thorsten Sommer via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu May 19 03:08:39 PDT 2016
Dear community,
I tried to create a kind of collector module which collects
strings by using a shared appender!string. Why? To collect KPIs
at a huge program across multiple classes and threads and store
it later as e.g. CSV file in order to analyse it by using R.
But I failed...
Attempt #1: I tried what I would do in Java and C#: Using a
Singelton pattern. But it was not as easy to create it in D and I
found out, that today the Singleton is considered as
anti-pattern. My conclusion was: Okay, that is right. Why should
I force OOP in D to realize a Singleton? I can use different
paradigm with D -- so just create a module with a shared
appender!string ... cf. attempt #2.
Attempt #2: https://dpaste.dzfl.pl/6035b6fdd4bd
My second attempt was to make my appender "sb" shared. But I got
this compiler error:
std/array.d(3118): Error: 'auto' can only be used as part of
'auto ref' for template function parameters
Do I used a wrong syntax or is this a bug?
Attempt #3: https://dpaste.dzfl.pl/1e5df9cf08c6
Okay, the third attempt. I searched around and found the
Appender!(shared(string)) syntax. That version compiles and it
runs fine. But the "sb" is not shared, because the "four" output
is missing (cf. dpaste).
Can anyone help me? I am stucked...
Best regards,
Thorsten
More information about the Digitalmars-d-learn
mailing list