enum str = "abc"; vs string str = "abc";

H. S. Teoh hsteoh at quickfur.ath.cx
Thu Jan 17 15:32:21 UTC 2019


On Thu, Jan 17, 2019 at 03:16:16PM +0000, Meta via Digitalmars-d wrote:
> On Thursday, 17 January 2019 at 06:00:09 UTC, Walter Bright wrote:
> > That's true for arrays, but for strings the compiler will emit only
> > one string, and everything else will refer to that.
> 
> While we have your ear, Walter, what about an enum that is an array of
> strings? Will an enum array of strings with length N behave the same
> way as a single string and only emit those N strings once, or will a
> new array be allocated each time the enum is used?

You could just check the disassembly yourself.  On my system, I found
that the strings themselves are only stored once. But the outer array is
allocated and repopulated each time, each time by a call to a druntime
function _d_arrayliteralTX.


T

-- 
Genius may have its limitations, but stupidity is not thus handicapped. -- Elbert Hubbard


More information about the Digitalmars-d mailing list