digitalmars.D - array literals and the read only segment
- Shachar Shemesh (11/11) Dec 11 2016 Hello everyone,
- Johan Engelen (4/5) Dec 11 2016 Which compiler(s) did you test?
- Shachar Shemesh (5/10) Dec 11 2016 DMD 2.072.1 and ldc 2.070.2
- Johan Engelen (21/25) Dec 12 2016 For LDC, it depends whether the variables are defined inside a
- Kagamin (6/7) Dec 12 2016 What's the issue? That array1 is in data section? That array2 is
Hello everyone, Please consider the following snippet: immutable ubyte[] array1 = [ 1, 2, 3, 4 ]; immutable ubyte[] array2 = cast(immutable ubyte[]) x"01 02 03 04"; Examining the resulting code, it is obvious that the literals initializing array2 are stored in the read only segment (.rodata), as they should be. It is equally obvious that array1 is stored in the data segment. This is bad for a variety of reasons. Is this a know issue? Shachar
Dec 11 2016
On Sunday, 11 December 2016 at 12:48:17 UTC, Shachar Shemesh wrote:Is this a know issue?Which compiler(s) did you test? -Johan
Dec 11 2016
On 11/12/16 21:03, Johan Engelen wrote:On Sunday, 11 December 2016 at 12:48:17 UTC, Shachar Shemesh wrote:DMD 2.072.1 and ldc 2.070.2 It's easy to verify. Just create a large array (1M) and check the segment sizes of the result. ShacharIs this a know issue?Which compiler(s) did you test? -Johan
Dec 11 2016
On Monday, 12 December 2016 at 06:28:09 UTC, Shachar Shemesh wrote:DMD 2.072.1 and ldc 2.070.2 It's easy to verify. Just create a large array (1M) and check the segment sizes of the result.For LDC, it depends whether the variables are defined inside a function or not. ``` immutable ubyte[] array1 = [ 1, 2, 3, 4 ]; // ends up in data section immutable ubyte[] array2 = cast(immutable ubyte[]) x"01 02 03 04"; // not in data section void foo() { // Both initializers are _not_ put in the data section. immutable ubyte[] array1 = [ 1, 2, 3, 4 ]; immutable ubyte[] array2 = cast(immutable ubyte[]) x"01 02 03 04"; } ``` The module-scope variable's initializer ending up in the data section is a bug I think, but I have not thought it through enough. -Johan
Dec 12 2016
On Sunday, 11 December 2016 at 12:48:17 UTC, Shachar Shemesh wrote:Is this a know issue?What's the issue? That array1 is in data section? That array2 is in rodata section? Or that they are in different sections? I suppose string literal goes to rodata because all string literals go there, and everything else goes to data.
Dec 12 2016