digitalmars.D.bugs - [Issue 24343] New: Read only data used to initialize objects that
- d-bugmail puremagic.com (31/31) Jan 17 https://issues.dlang.org/show_bug.cgi?id=24343
https://issues.dlang.org/show_bug.cgi?id=24343 Issue ID: 24343 Summary: Read only data used to initialize objects that are mostly zero Product: D Version: D2 Hardware: All OS: All Status: NEW Severity: enhancement Priority: P1 Component: dmd Assignee: nobody puremagic.com Reporter: bugzilla digitalmars.com Consider: struct S { int[100] x; } The compiler generates a static initializer for it. But since it is all zeros, it is allocated in the BSS segment and does not consume any memory in the DATA or READONLY sections in the executable. Even better, since the initializer is readonly, all the zero-initialized objects sit on top of each other in BSS, consuming only the memory used by the largest. When a zero initializer object is initialized, it is done with a memset(). For: struct T { int i = 3; int[100] x; } The initializer is not all zero, so it is placed in the READONLY section. Initialization of an object is performed by doing a memcpy() from this data. The idea of this issue is: 1. the .init data not be generated at all for the T 2. Object initialization should be done by a memset() followed by assignment to the non-zero members. Or simply do memberwise assignment. --
Jan 17