On 12/20/2011 6:23 AM, Andrei Alexandrescu wrote:
On 12/20/11 9:00 AM, Denis Shelomovskij wrote:
Now dmd have at least _two order of magnitude_ file size increase. I
posted that problem four months ago at "Building GtkD app on Win32
results in 111 MiB file mostly from zeroes".
[snip]
---
char arr[1024 * 1024 * 10];
void main() { }
---
[snip]
If described issues aren't much more significant than "static this()",
show me where am I wrong, please.

Using BSS is a nice optimization, but not all compilers do it and I know for a
fact MSVC didn't have it for a long time. That's probably why I got used to
thinking "poor style" when seeing a large statically-sized buffer with static
duration.

I'd say both issues deserve to be looked at, and saying one is more significant
than the other would be difficult.

First off, dmd most definitely puts 0 initialized static data into the BSS segment. So what's going on here?

1. char data is not initialized to 0, it is initialized to 0xFF. Non-zero data cannot be put in BSS.

2. Static data goes, by default, into thread local storage. BSS data is not thread local. To put it in global data, it has to be declared with __gshared.

So,

__gshared byte arr[1024 * 1024 *10];

will go into BSS.

There is pretty much no reason to have such huge arrays in static data. Instead, dynamically allocate them.

Reply via email to