Global runtime strings help
Jonathan Crapuchettes
jcrapuchettes at gmail.com
Mon Sep 26 12:57:21 PDT 2011
Thank you for the thought, but the problem here is that the file containing the
strings is only known at runtime from a command line argument. I also have some
global strings that need to be set from the database.
Thank you again,
JC
Jonathan M Davis wrote:
> On Friday, September 23, 2011 13:29:08 Jonathan Crapuchettes wrote:
>> I'm working on an application that requires a large number of strings that
>> only need to be loaded once at runtime and need to be accessible to all
>> threads throughout the execution of the program. Some of these strings are
>> variables like database host and username that need to be read from a file.
>>
>> Can anyone help me with an example how they might do this task?
>> Thank you,
>> JC
>
> immutable string1;
> immutable string2;
> immtuable string3;
>
> static shared this()
> {
> string1 = "the string";
> string2 = "the other string";
> string3 = funcThatGrabsStringFromFile();
> }
>
> immutable variables are implicitly shared. The shared module constructor will
> then initialize them before main runs, and all threads will have access to
> them.
>
> - Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list