January 17, 2019
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?
January 17, 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
January 17, 2019
On 1/17/2019 7:32 AM, H. S. Teoh wrote:
> You could just check the disassembly yourself.

It's a good practice to follow. I don't always remember what it does exactly, as it changes over time, and multiple people have contributed to it. I check the assembler output myself just to be sure.
1 2
Next ›   Last »