On 08/19/2013 03:18 AM, Borislav Kosharov wrote:> So if I want to have a string constant it is a lot better to declare it as:
>
> static immutable string MY_STRING = "Some string";
>
> Because it won't be duplicated?

enum is fine with strings.

It is a common space optimization of the compilers not to duplicate identical strings. The following program includes just one "hello world" in the compiled object file:

import std.stdio;

enum atModuleLevel = "hello world";

void foo()
{
    writefln(atModuleLevel);
}

void main()
{
    enum s = "hello world";
    writeln(s);
    writeln(s);
    writeln(atModuleLevel);
    foo();
}

Ali

Reply via email to