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.
Comment #1 by dfj1esp02 — 2024-01-25T19:50:57Z
TypeInfo could have a member
---
byte pattern;
---
so that struct S { char[100] x; } (sockaddr_un?) could still be initialized with memset.
Comment #2 by johanengelen — 2024-02-23T18:54:51Z
How will this code be treated?
```
const(void[]) f() {
return __traits(initSymbol, T);
}
```
Comment #3 by robert.schadek — 2024-12-13T19:32:39Z